在sproutcore2中可以实现递归集合吗?
Are Recursive Collections possible in sproutcore2?
我有一个可自定义的导航树,可以嵌套3层深。
模板:
<script type="text/x-handlebars" data-template-name="NavItemView">
<a {{bindAttr href="href" class="content.className"}}>{{content.name}}</a>
{{##if content.children}}
another collection here?
{{/if}}
</script>
<script type="text/x-handlebars">
{{collection App.NavItemsCollectionView contentBinding="App.navItemsController" tagName="ul"}}
{{view App.CreateLinkView id="new-link" placeholder="Name"}}
</script>
数据:
nav =[
{
"name": "Jethro Larson",
"children":[
{
"name":"Dashboard",
"href": "index.cfm"
}
]
},
{
"name":"Order Management",
"children":
[
{
"name":"OM Reports",
"children":
[
{
"name":"Status Updates",
"href":"index.cfm?blah"
}
]
}
]
}
];
js:
window.App = SC.Application.create();
App.NavItem = SC.Object.extend({
name: null,
href: '#',
});
App.navItemsController = SC.ArrayProxy.create({
content:[],
addMultiple: function(ar){
that = this;
$.each(ar,function(i,item){
that.pushObject(App.NavItem.create(item));
});
}
});
App.NavItemView = SC.View.extend({
tagName:'li'
,templateName: 'NavItemView'
});
App.NavItemsCollectionView = SC.CollectionView.extend({
itemViewClass: App.NavItemView
});
App.navItemsController.addMultiple(nav);
是否有一种方法来嵌套集合,这样我就可以链接dom到数据结构?
你可以做到这一点的方式是,通过把更多的逻辑到你的'NavItemView'模板,只是包括另一个集合视图在你写的地方"另一个集合在这里"。
如果你之前尝试过,它可能没有工作,因为在你的If语句中的双哈希字符。我已经在一个分层进度视图中使用了十个嵌套的级别。试着
<script type="text/x-handlebars" data-template-name="NavItemView">
<a {{bindAttr href="href" class="content.className"}}>{{content.name}}</a>
{{#if content.children}}
{{view App.NavItemsCollectionView contentBinding="content.children"}}
{{/if}}
</script>
<script type="text/x-handlebars">
{{view App.NavItemsCollectionView contentBinding="App.navItemsController" tagName="ul"}}
{{view App.CreateLinkView id="new-link" placeholder="Name"}}
</script>
相关文章:
- 数组在递归方法中设置为null
- Kendo:我该如何在树视图中创建一个递归的hieiarchy
- 递归使用 eval() 是检查程序执行的好方法吗?
- 使用递归、Ramda.js和无点样式重构字符串的getPermutations()
- 递归深度比较
- Eloquent JavaScript递归示例如何终止为返回1,但仍然输出指数值
- 递归函数中断
- 如何递归地获取嵌套对象中所有子对象的列表
- JavaScript 素数搜索无限递归
- 在递归生成器函数中,yield后面的*(星号/星号)语法意味着什么
- 递归|两个函数名
- 有没有一种方法可以在Javascript中进行可变递归currying
- 如何对不同的表递归使用以下代码
- 将jQuery对象传递到setTimeout递归函数中
- 如何使用promise返回从递归AJAX调用构建的集合
- backbone.js集合-如何为fetch定义成功回调(不过是递归的)
- 通过克隆n-1并在克隆上加上n,递归地找到集合Powerset的所有子集
- 在sproutcore2中可以实现递归集合吗?
- 主干集合递归地重复自身
- 如何得到多个集合的所有可能组合其中顺序递归地重要