敲除错误-未捕获错误:无法解析绑定. [英] knockout error - Uncaught Error: Unable to parse bindings.
问题描述
运行剔除代码时出现以下错误: 未捕获的错误:无法解析绑定. 消息:ReferenceError:度量未定义; 绑定值:模板:{名称:"measureDispTmpl",foreach:度量,如:食品"}
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' }
您可以在此处查看jsfiddle代码:
You can see the jsfiddle code here:
http://jsfiddle.net/nickbuus/eUufc/
当我单击+图标时,我希望调用addMeasure方法-以便可以向当前foodItem添加新度量并保存它.但是,当我尝试调用addMeasure时,该方法为:
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.
推荐答案
我更新了您的小提琴.在您的代码中,在viewModel的foodList中添加一个mesureItem. 这就是为什么食物模板不起作用的原因(因为它试图显示一个度量,而一个度量又不是度量属性).
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);
};
针对您的问题:
只需将其添加到addMeasure函数的末尾即可:
Just add this at end of the addMeasure function:
self.selectedItem(newItem);
希望对您有帮助.
这篇关于敲除错误-未捕获错误:无法解析绑定.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!