该小提琴重新创建了入门套件,并带有可更改模型的额外按钮。
http://jsfiddle.net/UjacC/1/ http://jsfiddle.net/UjacC/1/
但是,当单击“更改”时,数组会更改,但视图不会更新。为什么?
<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;
}
});
你需要使用 Embers 而不是 stuff.pushpushObject http://emberjs.com/api/classes/Ember.MutableArray.html#method_pushObject这将通知对象的侦听器它发生了更改。
EDIT:
这是更新后的 jsfiddle:http://jsfiddle.net/UjacC/2/ http://jsfiddle.net/UjacC/2/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)