开发者

Making properties observable in array with Knockout.js Mapping Plugin

开发者 https://www.devze.com 2023-04-01 12:39 出处:网络
When I call ko.mapping.fromJS(model) it creates a blank array.I am trying to create an observable array with observable properties.The initial model variable object as a string looks like this \"[{\"K

When I call ko.mapping.fromJS(model) it creates a blank array. I am trying to create an observable array with observable properties. The initial model variable object as a string looks like this "[{"Key"开发者_StackOverflow社区:"test","Speeches":[{"Text":"test"}]}]". Why is the fromJS method returning an empty array [] ?


If your model is in JSON (string representation), then you need to use ko.mapping.fromJSON(model).

Otherwise, it should work fine. I know that console.log on an observableArray in Chrome shows [], so maybe the data is there.

Here is a sample that shows both ways and that the data is valid: http://jsfiddle.net/rniemeyer/PBhG3/

0

精彩评论

暂无评论...
验证码 换一张
取 消