与启用属性的敲除绑定问题

时间:2013-03-14 11:32:04

标签: binding knockout.js

请考虑以下事项:

<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/

1 个答案:

答案 0 :(得分:1)

您的IsSelected不是可观察的 - this worked for me