Error in knockout mapping JSON read

前端 未结 1 1926
星月不相逢
星月不相逢 2021-01-17 02:13

i am using knockout on web application which displays the data with a foreach (all needed libraries are included)

and i get the following error:

Err         


        
相关标签:
1条回答
  • 2021-01-17 02:33

    The problem is most likely that you are using fromJSON when you really mean fromJS. $.getJSON will already create an object for you while ko.mapping.fromJSON reads in a JSON string. ko.mapping.fromJS reads in a Javascript Object.

    See this JSFiddle for more: http://jsfiddle.net/hB3Rm/

    Essentially, change this line:

    Listing_ViewModel = ko.mapping.fromJSON(data);
    

    to this line:

    Listing_ViewModel = ko.mapping.fromJS(data);
    
    0 讨论(0)
提交回复
热议问题