2

我有一个foreach使用 observablearray,名为CertificateDetailsToShow. CertificateDetailsToShow有一个名为 的列LoanNum。嵌套在 foreach 中,我有一个选择列表,它使用一个名为DDABankNums 的 observablearray(填充选择列表选项)。它有一个属性叫做mLoanNum。我想根据LoanNum两个 observablearrays ( DDABankNums.mLoanNum = CertificateDetailsToShow.LoanNum) 过滤选择列表中显示的内容。我怎样才能做到这一点?

我的视图代码-

<tbody data-bind="foreach: CertificateDetailsToShow">
  <tr id="Tr1" style="cursor: pointer">
    <td>
      <ul style="width: 100%">
        <h5 class="muted"><b>Loan:&nbsp;<span class="muted" data-bind="text: LoanNum"></span>&nbsp;(<span data-bind="    text: CurrType"></span>)</b>
          <select id="Select1" style="margin-top: 0px; height: 24px; width: 160px !important"
            data-bind="options: $parent.DDABankNums, optionsText: 'AccountName', value: $parent.mLoanNum, optionsCaption: $data.LoanNum">
          </select>
        </h5>
      </ul>
    </td>
  </tr>
</tbody>
4

1 回答 1

5
<tbody data-bind="foreach: CertificateDetailsToShow">
  <tr>
    <td>
      Loan: <span data-bind="text: LoanNum"></span> (<span data-bind="text: CurrType"></span>)

      <select
        data-bind="options: $parent.filter($parent.DDABankNums, $data.LoanNum), optionsText: 'AccountName', optionsValue: 'myDDABankNumValueAttributeName'">
      </select>
    </td>
  </tr>
</tbody>

ViewModel 包含此方法:

self.filter = function(ddaBankNums, loanNum) {
    return ddaBankNums().filter(function(ddaBankNum) {
         return ddaBankNum.mLoanNum == loanNum;
    });
}
于 2013-07-30T15:43:45.800 回答