我有foreach
使用名为CertificateDetailsToShow
的observablearray。 CertificateDetailsToShow
有一个名为LoanNum
的列。嵌套在foreach中,我有一个选择列表,它使用一个名为DDABankNum
的observablearray(填充选择列表选项)。它有一个名为mLoanNum
的属性。我想根据observablearrays(LoanNum
)中的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: <span class="muted" data-bind="text: LoanNum"></span> (<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>
答案 0 :(得分: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;
});
}