似乎敲除没有正确映射数组中对象的属性.
从chrome控制台中查看此示例:
> var viewmodel = ko.mapping.fromJS({list:[]}); undefined > viewmodel.list().unshift({ name : ko.observable("Foo") }); 1 > viewmodel.list()[0].name(); "Foo" > var js = ko.mapping.toJS(viewmodel); undefined > js.list[0].name; undefined
所以正在创建javascript对象,但是’name’属性没有被映射.
任何想法都非常欢迎!
解决方法
从
http://knockoutjs.com/documentation/plugins-mapping.html开始,关于toJS()函数:
This will create an unmapped object containing only the properties of the mapped object that were part of your original JS object.
由于“名称”不是您映射的原始对象的一部分,因此它不会被取消映射.您需要告诉映射插件包含此特定属性:
var js = ko.mapping.toJS(viewmodel,{ include: ['name'] });