2014-10-16 73 views

回答

0

在同一引导,其中禁用原型扩展的作用是为arrays解释,据说

Native arrays will no longer implement the functionality needed to observe them. If you disable prototype extension and attempt to use native arrays with things like a template's {{#each}} helper, Ember.js will have no way to detect changes to the array and the template will not update as the underlying array changes.

Additionally, if you try to set the model of an Ember.ArrayController to a plain native array, it will raise an exception since it no longer implements the Ember.Array interface.

You can manually coerce a native array into an array that implements the required interfaces using the convenience method Ember.A:

因此改变你的model钩作为

App.ApplicationRoute=Ember.Route.extend({ 
    model:function(){ 
    return Ember.A(["one","two","three"]); 
    } 
}); 

,并在您的模板,

<ul> 
{{#each model}} 
    <li>{{this}}</li> 
{{/each}} 
</ul> 

更新jsbin:http://jsbin.com/hayata/1/edit

现在没有错误被抛出的余烬,但有些错误是从其它脚本抛出。

一旦你修好了,它会没事的。

+0

你说得对。我已阅读有关数组,并忘记使用Ember数组而不是使用本地数组。但是你可能会在控制台中看到异常:'未捕获的RangeError:无效的数组长度'出现在ember.js中。 – Susai 2014-10-16 13:08:54

相关问题