这个小提琴重新创建了入门套件,并带有可以改变模型的额外按钮。
但是,单击更改时,阵列会更改,但视图不会更新。为什么呢?
<title>Ember Starter Kit</title>
<body>
<script type="text/x-handlebars">
<h2>Welcome to Ember.js</h2>
<button id="btnChange">change model</button>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
<ul>
{{#each item in model}}
<li>{{item}}</li>
{{/each}}
</ul>
</script>
<script>
$(document).ready(function(){
console.log(stuff);
$("#btnChange").click(function(){
stuff.push("d");
console.log("change",stuff);
});
});
</script>
</body>
App = Ember.Application.create();
var stuff = ["a","7","b","c"];
App.Router.map(function() {
// put your routes here
});
App.IndexRoute = Ember.Route.extend({
model: function() {
return stuff;
}
});
答案 0 :(得分:7)
而不是stuff.push,你需要使用Embers pushObject
,它会通知一个对象的侦听器它有变化。
这是更新的jsfiddle:http://jsfiddle.net/UjacC/2/