【发布时间】:2014-09-08 15:53:47
【问题描述】:
在我的 js 中,我正在调用一个函数,点击这里是我的函数
function PopulateBranch(branchAreaName) {
var nodePath = "/content/eng/phone-numbers/jcr:content/content-page/wireframe";
$.ajax({
data: "action="+"getBranch"+ "&nodePath=" + nodePath + "&nodeName=" + branchAreaName,
url: '/bin/branchlocator/crud' ,
dataType: 'json',
type: 'GET',
success: function (data) {
self.PopulateBranch = ko.computed(function(){
ko.utils.arrayForEach(data, function(item){
branchView.Branches.push(new Branch(item));
});
});
},
error: function (exception) {
alert("fail");
}
});
};
我在视图模型中调用此函数,但当我调用此函数时出现此错误
Uncaught Error: Cannot write a value to a ko.computed unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters.
任何解决方案??
【问题讨论】:
-
你认为
self.PopulateBranch = ko.computed(...)是做什么的?请提供更多代码(例如branchView.Branches的定义,外部PopulateBranch是一个全局函数,你是如何调用PopulateBranch)。 -
是的,它是全局函数...我会尝试为您提供更多代码
-
jsfiddle.net/sohimohit/43zkoszu/18 这是小提琴链接,我在点击显示分支时调用函数
标签: javascript knockout.js knockout-3.0