Recursive view in handlebars template not working after upgrading to Ember 0.9.6

大兔子大兔子 提交于 2019-11-30 15:59:01

I think the issue is that by creating the controller inside the class App.Menu the controller property is the same for every concrete instance of App.Menu, see Understanding Ember.Object.

I've moved the binding to the specific controller out of the view class and it works, see http://jsfiddle.net/pangratz666/DgG9P/

Handlebars:

<script type="text/x-handlebars" data-template-name="Menu" >
    <li>
        {{page.menuTitle}}
        {{#each page.childrenPages}}
            {{view App.Menu pageBinding="this"}}
        {{/each}}
    </li>
</script>

<script type="text/x-handlebars">
    {{view App.Menu pageBinding="App.mainPage" }}
</script>

JavaScript:

App = Ember.Application.create({});

App.Menu = Em.View.extend({
    tagName: 'ul',
    templateName: 'Menu'
});

App.mainPage = Ember.Object.create({
    menuTitle: 'main page',
    childrenPages: [Ember.Object.create({
        menuTitle: 'subtitle 1',
        childrenPages: [Ember.Object.create({
            menuTitle: 'subtitle 1 - child 1'
        })]
    }), Ember.Object.create({
        menuTitle: 'subtitle 2',
        childrenPages: [Ember.Object.create({
            menuTitle: 'subtitle 2 - child 1'
        })]
    })]
});​
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!