我有下一个模型:
var simpleModel = function(){
var self = this;
self.name = "Simple model";
self.attributes = {
attr1: ko.observable("1"),
attr2: ko.observable("2"),
attr3: ko.observable("3")
};
}
我希望能够枚举attributes
该模型的属性并显示键和值,如下所示:
<div>
<span>attr1</span><span>1</span>
<span>attr2</span><span>2</span>
<span>attr3</span><spam>3</span>
</div>
我试图根据javascript在对象上使用时的for循环行为来解决这个问题,但失败了:
<div data-bind="foreach: { data: designAttributes, as: 'dAttr' }">
<span data-bind="text: $index"></span>
<span data-bind="text: dAttr[$index]"></span>
</div>