0
幫助請幫助。我有22個物體,5個父母和17個孩子。 我無法得到ui li的孩子。使用數據綁定 敲出js。僅顯示5位父母。提前致謝。獲取列表的孩子ui li dropdown knockout.js數據綁定
Index.js
self._routes = ko.observableArray([]);
self._child = ko.observableArray([]);
for (var i = 0; i < backend.user().UserScreens.length; i++) {
var str = backend.user().UserScreens[i].addOn; //add icon
str = str.substring(0, str.length - 1); //trim last character ','
if (backend.user().UserScreens[i].isParent || backend.user().UserScreens[i] == null) {
self._routes.push({
route: backend.user().UserScreens[i].linkURL,
title: backend.user().UserScreens[i].description,
moduleId: 'modules/' + backend.user().UserScreens[i].linkURL.replace(/[\n\r]+/g, '').replace(/\s{2,10}/g, ' ') + '/index',
nav: true,
_icon: 'fa ' + str,
_id: '#' + backend.user().UserScreens[i].id
});
}
else {
self._child.push({
childRoute: backend.user().UserScreens[i].linkURL,
childtitle: backend.user().UserScreens[i].description,
childmoduleId: 'modules/' + backend.user().UserScreens[i].linkURL.replace(/[\n\r]+/g, '').replace(/\s{2,10}/g, ' ') + '/index',
childNav: true,
childIcon: 'fa ' + str,
childId: '#' + backend.user().UserScreens[i].id
});
}
}
的Index.html
<ul class="nav">
<li data-bind="foreach: _routes">
<a data-bind="attr: { href: _id }"><span data-bind="attr: {class: _icon}"></span>
<span class="sidebar-title" data-bind="text: title"></span><span class="caret"></span>
</a>
<ul data-bind="foreach: _child, attr: {id: childId}" class="nav sub-nav">
<li><a href="#" data-bind="attr: {href: '#' + childRoute}">
<span data-bind="attr: {class: _icon}"></span>
<span data-bind="text: childtitle"></span></a>
</li>
</ul>
</li>
</ul>
謝謝先生。新手在knockout.js。 :) –