It seems I can’t get the button generated in the template loop #eachto associate the click action with the corresponding model. Here is a brief demonstration of the problem ...
Application Setup Ember.js:
window.Contacts = Ember.Application.create();
Contacts.Person = Ember.Object.extend({
first: '',
last: '',
save: function() {
}
});
Contacts.contactsList = Ember.ArrayController.create({
content:[],
init: function() {
this.pushObject( Contacts.Person.create({
first:'Tom',
last:'Riddle'
}));
}
});
Template:
<script type="text/x-handlebars">
{{
<li>
{{view Ember.TextField valueBinding="first" viewName="firstname"}}
{{view Ember.TextField valueBinding="last" viewName="lastname"}}
<button {{action "save" on="click"}}>Save</button>
</li>
{{/each}}
</script>
Problem:
So, the idea in this simple demo scenario is that the “Save” button for each record will trigger an action to save the state of its own model. However, when you click the Save button, an error message appears:
Uncaught TypeError: Cannot call method 'call' of undefined
, "" save . , , . , - , "" undefined. - ? ?
!