-1

I have the following knockoutjs code with 3 checkboxes.

http://jsfiddle.net/gzfff/2/

The issue here is that the checkboxes are not being binded correctly with the json data.

Any clue?

HTML

<form>
    <div>
        <div>
            <label><input type="checkbox" data-bind="checked: properties" value="1" />Property ABC</label><br/>
            <label><input type="checkbox" data-bind="checked: properties" value="2" />Property CON</label><br/>
            <label><input type="checkbox" data-bind="checked: properties" value="3" />Property ZZZ</label>
        </div>
    </div>
</form>

<hr/>

<div data-bind="text: ko.toJSON(properties)"></div>​

JS

var jsonData= [1,2];

var App = function (jsondata) {
    var self = this;

    self.properties = ko.observableArray(jsondata);
};
var appViewModel = new App(jsonData);
ko.applyBindings(appViewModel);​

Thanks

4

1 回答 1

2

换行

var jsonData= [1,2];

var jsonData= ["1","2"];

http://jsfiddle.net/hE92D/

于 2012-08-14T19:37:04.467 回答