sproutcore2 中可以递归收集吗?
我有一个可自定义的导航树,可以嵌套 3 层深度。
Templates:
<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>
data:
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 链接到数据结构?
I have a customizable navigation tree that can be nested 3 levels deep.
Templates:
<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>
data:
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);
Is there a way to nest collections so I can link the dom to the data structure?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实现此目的的方法是,通过将更多逻辑放入“NavItemView”模板中,只需在您编写“此处另一个集合”的位置包含另一个集合视图。
如果您之前尝试过,则可能由于 if 语句中的双散列字符而不起作用。我已经在分层进度视图中使用了十个嵌套级别。尝试
作为车把模板。
The way you can achieve this is, by putting more logic into your 'NavItemView' template, just include another collection-view at the place you've written "another collection here".
If you've tried that before it might have not worked because of the double hash-char in your if-statement. I've used this already with ten nested levels in a hierarchical progress view. Try
as handlebars template.