admin 管理员组文章数量: 1086019
I'm close to going nuts about this now and figured it'd be simple, however, there must be something I'm missing...
I've got a multidimensional array in a ko.observableArray, in which is so:
Site -> Company -> Job
For my data binds, data-bind="text: Site().Name"
is fine, as you would expect. However, I can't access the sub-arrays by data-bind="text: Site().Company().Name"
or data-bind="text: Site().Company.Name"
.
Has anyone else had the same issue, or is there something I'm doing drastically wrong? The objects are 100% being loaded into the array properly as I can see them in the console.
I'm close to going nuts about this now and figured it'd be simple, however, there must be something I'm missing...
I've got a multidimensional array in a ko.observableArray, in which is so:
Site -> Company -> Job
For my data binds, data-bind="text: Site().Name"
is fine, as you would expect. However, I can't access the sub-arrays by data-bind="text: Site().Company().Name"
or data-bind="text: Site().Company.Name"
.
Has anyone else had the same issue, or is there something I'm doing drastically wrong? The objects are 100% being loaded into the array properly as I can see them in the console.
Share Improve this question asked Mar 12, 2012 at 16:01 Chris DixonChris Dixon 9,1676 gold badges38 silver badges68 bronze badges1 Answer
Reset to default 9If I understand your problem correctly and a Site
contains an observableArray of Company
objects and each Company
object contains an observableArray of Job
objects, then your approach will not work.
data-bind="text: Site().Company().Name"
is trying to get the Name
property of an observableArray that happens to contain Company
objects. You could however write data-bind="text: Site().Company()[0].Name"
to get the name of the first Company
.
A more mon approach would be to iterate through the items. Something like:
<!-- ko with: Site -->
Site name is <span data-bind="text: Name"/>
<ul>
<!-- ko foreach: Company -->
<li>Company name is <span data-bind="text: Name"/>
<!-- ko foreach: Job -->
<li>Job name is <span data-bind="text: Name"/>
</li>
<!-- /ko -->
</li>
<!-- /ko -->
</ul>
<!-- /ko -->
See http://knockoutjs./documentation/foreach-binding.html for more details.
Hope this is what you are looking for and apologies if I have misunderstood your question.
本文标签: javascriptKnockout JSMultidimensional observableArrays and displaying subarray dataStack Overflow
版权声明:本文标题:javascript - Knockout JS - Multidimensional observableArrays and displaying sub-array data - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744042075a2523437.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论