1
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 の場合に条件付きで表示されるループ内に 2 つ目の div コンテナーを作成できますか?

4

2 に答える 2