I have the following data-binding with knockout. The web service returning xml so i did the mapping from xml to json as follow:
var jsonResponse = xmlToJson(msg);
ko.mapping.fromJSON(jsonResponse.Category.SubCategories.SubCategory[0], {}, viewModel.dataRow);
When i debug in the chrome browser i can display the name property as follow:
jsonResponse.Category.SubCategories.SubCategory[0].Name['#text']: "Basket"
However during the data-binding in markup, I am having an error.
i tried both:
<li data-bind="text: Name()"></li> and <li data-bind="text: Name"></li>
Console log ERROR:
Message: Name is not defined
Anyone knows how to solve the #text during data-binding in knockout ?
EDIT:
@Robert - you almost shed the light i modified the code as follow, it has no console log err but it does not display anything, any ideas?
js:
var jsonResponse = xmlToJson(msg);
viewModel.dataRow = ko.mapping.fromJSON(jsonResponse.Category.SubCategories.SubCategory[0]);
markup (now it has context):
<div data-bind="with: dataRow">
<ul>
<li data-bind="text: Name"></li>
</ul>
</div>