我最近开始学习 ember.js,由于某种原因我无法调用我的 Controller
App = Ember.Application.create();
App.Router.map(function() {
this.route('about');
});
App.IndexRoute = Ember.Route.extend({
model: function() {
return ['red', 'yellow', 'blue', 'pie','koala'];
}
});
App.IndexController = Ember.Controller.extend({
sortedModel : function(){
alert("this works");
}
});
app.js
<script type="text/x-handlebars" id="index">
<ul>
{{#each sortedModel as |item|}}
<li>{{item}}</li>
{{/each}}
</ul>
</script>
我尝试按照教程通过在循环中引用sortedModel来调用它 这可能是非常愚蠢的事情,但对于我的生活来说,我似乎看不到它,我严格按照教程进行操作,没有它就无法继续
最佳答案
尝试:
用 .property() 标记函数
App.IndexController = Ember.Controller.extend({
sortedModelAlertOnly : function(){
alert("this works");
}.property(),
sortedModel : function(){
return this.get('model').sort();
}.property('model')
});
关于javascript - Controller 调用失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39163192/