我的论文中有3个部分knockoutjs绑定(bind)
var model1= function()
{
self = this;
//somemethods here..
}
var model2= function()
{
self = this;
self.status = null;
self.id = ko.observable(1);
self.processingStatus = function ()
{
self.status = setInterval(function(){
var id = self.userId();//**self conteine link to model3**
}, 1100);
}
//somemethods here..
}
var model3= function()
{
self = this;
//somemethods here..
}
var m1 = new model1();
ko.applyBindings(m1, document.getElementById("id1"));
var m2 = new model2();
ko.applyBindings(m2, document.getElementById("id2"));
var m3= new modelHistory();
ko.applyBindings(m3, document.getElementById("id3"));
model2中的processingStatus
方法内部,self指针大陆model3的数据。
它会发生什么以及如何在每个模型类中拥有不同的自指针?
最佳答案
您忘记了自变量的“var”。
var self = this;
关于JavaScript 和 knockoutjs 此关键字的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22043825/