2017-03-02 74 views
1

內如何能在模板中我懶負載的關係?EmberJS - 懶加載模板

// models/folder.js 
export default DS.Model.extend({ 
    children: DS.hasMany('item', { inverse: 'parent', async: true }) 
}); 

// models/item.js 
export default DS.Model.extend({ 
    parent: DS.belongsTo('folder', { inverse: 'children', async: true }) 
}); 

在這一點上的文件夾被加載(except of his children),而且從來沒有加載的兒童。

我想就當我運行{{folder.children}}模板內EmberJS加載一個文件夾的孩子。

+0

它應該被加載。 '{{folder.children.length}}' –

+0

不,它不會加載。看看這個例子:https://emberjs.jsbin.com/cofiqikoho/1/edit?html,js,console,output EmberJS沒有嘗試加載'items'。 – Charles

+0

在您提供的jsbin中,沒有子負載數據。推送一些有效載荷的兒童,那麼你可以看到 –

回答

0

你可以把UI的孩子一節中if幫手。然後,如果條件爲真,你的孩子們承諾,fullfilled。

<button {{action (mut showChildren) true}}>Expand</button> 

{{#if showChildren}} 
    {{#each parent.children as |child|}} 
    <span>{{child.name}}</span> 
    {{/each}} 
{{/if}} 
+0

那樣? https://emberjs.jsbin.com/liponejoje/1/edit?html,js,console,output – Charles

+0

@Charles我更新了[jsbin](https://emberjs.jsbin.com/radufetowu/1/edit?html ,js,console,output) –

+0

我不想加載父列表的子項。 – Charles