var ready;
ready = function() {
var imageChooser, productChooser;
productChooser = function() {
var self;
self = this;
self.quantityId = ko.observable(1);
self.quantityText = ko.observable('QTY');
self.genderId = ko.observable(1);
self.sizeId = ko.observable(1);
self.colorId = ko.observable(1);
self.fullSize = ko.observable('SIZE');
this.setGenderAndSize = function(stringtoparse, thestring) {
var values;
values = stringtoparse.split(":");
self.fullSize("SIZE: " + thestring);
self.genderId(values[0]);
self.sizeId(values[1]);
};
this.setQuantity = function(quantity) {
self.quantityId(quantity);
self.quantityText("QTY: " + quantity);
};
};
imageChooser = function() {
this.clicked = ko.observable();
this.setBigImage = (function(message) {
alert(message);
}).bind(this);
};
ko.applyBindings(new productChooser(), $("#genderAndSizeChooser")[0]);
ko.cleanNode($('#genderAndSizeChooser')[0]);
return ko.applyBindings(new imageChooser(), $('#imageChooser')[0]);
};
$(document).on('ready page:load', ready);
我目前有这个代码。不知何故,ko.cleanNode
代码:
ko.cleanNode($('#genderAndSizeChooser')[0]);
生成错误:
Uncaught TypeError: Cannot read property 'nodeType' of undefined
任何人都知道错误的原因吗?
答案 0 :(得分:5)
看起来它实际上找不到ID为genderAndSizeChooser
的元素。
ko.applyBindings
调用会收到undefined
并像正常一样对正文应用绑定,因此不会出错,但使用ko.cleanNode
调用undefined
会导致错误。