ember.js - Ember local live list -
i try simple application using ember. index controller:
app.indexcontroller = ember.objectcontroller.extend({ schools: [{name:"old school"}], actions:{ add: function(){ var schools = this.get("schools"); schools.push({name: 'new school'}); this.set("schools",schools); } } });
index template:
<script type="text/x-handlebars" data-template-name="index"> <button type="button" {{action "add"}}>add school</button> <ul> {{#each school in schools}} <li>{{school.name}}</li> {{/each}} </ul> </script>
when lunch application on start see:
- old school
and when hit add button nothing happens, why?
you need use pushobject
in order ember know value has been added list. , there no need set afterward.
add: function(){ var schools = this.get("schools"); schools.pushobject({name: 'new school'}); }
Comments
Post a Comment