function MyViewModel() {
var self = this;
this.addPerson = function () {
this.PersonIdList.push(0);
}
this.showSecondSection = ko.computed(function() {
// need logic here?
}, this);
this.PersonIdList = ko.observableArray();
this.PeopleChoices = ko.observableArray([
{
"Id": 1,
"Name": "Person A"
},
{
"Id": 2,
"Name": "Person B"
},
{
"Id": 3,
"Name": "Person C"
},
);
}
<!-- ko foreach: PersonIdList -->
<div class="container" style="margin-bottom: 5px;">
<select id="idList" data-bind="options: $root.PeopleChoices, optionsValue: 'Id', optionsText: 'Name', optionsCaption: '-- Please Select --', value: ??"></select>
</div>
<div data-bind="visible: showSecondSection">Hi</div>
<!-- /ko -->
<a href="javascript:void(0);" data-bind="click: addPerson">Add person</a>
我想知道是否可以将此块数据绑定到 PersonIdList 中的项目?另外,如果 Id = 3,我可以在循环内创建一个有条件可见的第二个 div 容器吗?