knockout error - Uncaught Error: Unable to parse bindings.

▼魔方 西西 提交于 2019-12-24 00:35:20

问题


I get the following error when running my knockout code: Uncaught Error: Unable to parse bindings. Message: ReferenceError: measures is not defined; Bindings value: template: { name: 'measureDispTmpl', foreach: measures, as: 'food' }

You can see the jsfiddle code here:

http://jsfiddle.net/nickbuus/eUufc/

When I click the + icon I want the addMeasure method to be called - so that I can add a new measure to the current foodItem and save it. But when I try to call the addMeasure then the method:

 self.addMeasure = function (myItem)  

is never called and I get the above error.


回答1:


I updated your fiddle. In your code you add a mesureItem in the foodList of the viewModel. That's why the food template doesn't work (because it tries to show an measure and a measure doesn't an measures property).

self.addMeasure = function (myItem) {
    var foodIte = self.selectedItem();
    var newItem = new MeasureItem();
    // mine 
    myItem.measures.push(newItem);
    self.selectedItem(newItem);
   // your :
   //self.list.push(newItem);
};

See fiddle

In response to your question :

Just add this at end of the addMeasure function:

self.selectedItem(newItem);

I hope it helps.



来源:https://stackoverflow.com/questions/16978731/knockout-error-uncaught-error-unable-to-parse-bindings

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