考虑以下:
<div data-bind="with: QuoteSelectedViewModel">
selected quote is : <span data-bind="text: ProductName"></span>
<!-- ko foreach: CoverQuotesViewModel -->
<br/>
<input type="checkbox" data-bind="checked: IsSelected"></input>
<input type="text" data-bind="value: Label, enable: IsSelected"></input>
<!-- /ko -->
</div>
QuoteSelectedViewModel 为:
{
"ProductName": "Perfect",
"MonthPrice": 0,
"QuarterPrice": 0,
"BiannualPrice": 0,
"YearPrice": 0,
"CoverQuotesViewModel": [ {
"ProductName": "Select",
"Label": "Première Assistance 24h/24 (GRATUITE)",
"IsVisible": true,
"IsMandatory": true,
"IsSelected": false,
"IsChoice": false,
"IsComposite": false,
"YearPrice": "451451",
"BiannualPrice": 0.49,
"QuarterPrice": 0.2475,
"MonthPrice": 0.08333333333333333,
"Childs": [],
"SelectedCoverQuote": null
},
{
"ProductName": "Select",
"Label": "Assistance PLUS 24h/24",
"IsVisible": true,
"IsMandatory": false,
"IsSelected": true,
"IsChoice": false,
"IsComposite": false,
"YearPrice": 36.0646,
"BiannualPrice": 18.2182,
"QuarterPrice": 9.20205,
"MonthPrice": 3.098333333333333,
"Childs": [],
"SelectedCoverQuote": null
}]
}
请参阅 jsfiddle 上的代码:http: //jsfiddle.net/graphicsxp/j8HdW/4/
问题是选中和取消选中复选框不会更新模型,因此它不会更新文本框。
要使演示工作,首先单击“获取报价”按钮,然后单击“选择报价”按钮
知道有什么问题吗?
编辑
好的,由于 jsfiddle 过于复杂,这里有一个简化版本:http: //jsfiddle.net/graphicsxp/WCA5f/