Ember不更新模型更改的视图 [英] Ember not updating the view on model change
本文介绍了Ember不更新模型更改的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个小提琴有重新创建的入门工具,带有改变模型的额外按钮。
This fiddle has the starter kit recreated, with and extra button that alters the model.
但是,当单击更改时,数组更改,但视图尚未更新。为什么?
However, when clicking change, the array changes, but the view is not being updated. Why?
<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;
}
});
推荐答案
而不是stuff.push你需要使用Embers <一个href =http://emberjs.com/api/classes/Ember.MutableArray.html#method_pushObject =noreferrer> pushObject
将会通知对象的听众有一个变化。
Instead of stuff.push you need to use Embers pushObject
which will notify listeners of an object that there was a change to it.
这是更新的jsfiddle: http://jsfiddle.net/UjacC/2/
Here's the updated jsfiddle: http://jsfiddle.net/UjacC/2/
这篇关于Ember不更新模型更改的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文