KnockOut Mapping Hierarchical JS object

心已入冬 提交于 2019-12-04 14:55:11

The problem was that you had a p tag nested within another. The template engine couldn't parse this incorrect markup.

You were also using a with binding when I think you wanted another foreach.

<p data-bind="foreach:sentences">
        <span data-bind="text:id"></span>
        <span data-bind="foreach:words">
            <span data-bind="text:text"></span>                   
        </span>
</p>

Lastly the sentence model can be reduced to

var mySentenceModel = function(data) {
    var self = this;
    ko.mapping.fromJS(data, wordMapping, self);
}

You don't need to define the id etc as it's all taken care of by the mapping plugin.

http://jsfiddle.net/madcapnmckay/6hMA3/

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!