2

I have an ember.js prototype, which was running fine until now. Since my last deployment I have been consistently getting the error Uncaught TypeError: Cannot read property 'hash' of undefined.

app.js file

// Application
Welcome = Ember.Application.create({
    ready : function() {
    }
});

// Model
Welcome.Ticket = Ember.Object.extend({
    id : null,
    buyerPartyId : null,
    name : null,
    priority : null,
    description : null,
    comment : null
}); 

// Controller
Welcome.ticketsController = Ember.ArrayController.create({
    content : [],

    loadTickets : function() {
        var self = this;
        $.getJSON('url here', function(
                data) {
            for ( var i = 0; i < data.serviceRequest.length; i++) {
                self.pushObject(Welcome.Ticket.create(data.serviceRequest[i]));
            }
        });
    }
});

Index.html

<!doctype html>
<html>
<head>
<title>Ticket List</title>
<link rel="stylesheet" href="css/normalize.css">
<script
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="js/libs/ember-0.9.5.min.js"></script>
<script src="js/app.js"></script>
</head>
<body>
    <h1>Ticket List</h1>
    <script type="text/x-handlebars">
    {{#view Ember.Button target="Welcome.ticketsController" action="loadTickets"}}
        Load Tickets
    {{/view}}

    {{#each contentBinding="Welcome.ticketsController" tagName="ul"}}
        <b>{{content.id}}</b> - {{content.buyerPartyId}}, <i>{{content.name}}</i>
    {{/each}}
</script>
</body>
</html>

I am sure that I am overlooking something simple !! Any suggestions would be appreciated !!

Here is the error stack from Chrome dev console.

Uncaught TypeError: Cannot read property 'hash' of undefined ember-0.9.5.min.js:13
(anonymous function) ember-0.9.5.min.js:13
(anonymous function)
b.VM.template ember-0.9.5.min.js:9
Ember.View.Ember.Object.extend.render ember-0.9.5.min.js:12
Ember.View.Ember.Object.extend.renderToBuffer ember-0.9.5.min.js:12
Ember.View.Ember.Object.extend.createElement ember-0.9.5.min.js:12
Ember.View.states.preRender.insertElement ember-0.9.5.min.js:12
Ember.View.Ember.Object.extend.invokeForState ember-0.9.5.min.js:12
c ember-0.9.5.min.js:10
j ember-0.9.5.min.js:10
f.flush ember-0.9.5.min.js:10
f.end ember-0.9.5.min.js:10
Ember.run.end ember-0.9.5.min.js:10
i ember-0.9.5.min.js:10
1
  • Might help if you point to which line is throwing the error ... Commented Sep 1, 2012 at 7:11

1 Answer 1

2

AFAIK, with {{each}}, you need to provide the controller directly. Something like:

{{#each Welcome.ticketController}}
{{/each}}

Take a look at this jsFiddle http://jsfiddle.net/lifeinafolder/nVr4r/. Its not throwing the error anymore.

"Load Tickets" button wont work as you dont have a url yet.

Emberjs documentation has a couple of examples using {{each}} too. You should take a look.

Also, you might wanna update your emberjs. In the ember world, 0.9.5.min is pretty old :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.