0
这是我在stackoverflow中的第一篇文章。绑定不起作用
我是新来的ember.js,我一直在研究ember.js。
我正在构建一个小应用来学习ember.js,但绑定不起作用。
请给我一个帮助!
#------------------------Controller------------------------
App.ApplicationController = Ember.Controller.extend();
App.monstersController = Ember.ArrayProxy.create({
content:[],
//some code to add model instances to content...
counter: function(){
var content = this.get('content');
return content.get('length');
}.property('length')
});
#------------------------View------------------------
App.StatsView = Ember.View.extend({
counterBinding : 'App.monstersController.counter',
#------------------------HTML------------------------
<script type="text/x-handlebars" data-template-name="application">
//some code here
{{#view App.StatsView}}Counter: {{counter}}{{/view}}
//I'm expecting the length of content array in App.monstersController above.
//some code here
</script>
非常感谢你! 我将{{counter}}更改为{{view.counter}},它工作正常! 林困惑我为什么需要添加“查看”,虽然... 我会继续研究烬。 再次,非常感谢! – crzyonez777
模板具有从中提取值的上下文。默认情况下,它被设置为连接到视图的控制器。在Ember的早期版本中,上下文实际上是视图本身,但是通过引入路由器和控制器,将上下文设置为视图所代表的对象而不是视图本身更有意义 –
哦,我明白了!非常感谢!!! – crzyonez777