我正在尝试使用knockout js的购物车编辑器的例子。此处
我想在java脚本提示出现时,立即删除用户添加的所有行。我以为把cartLine数组设置为nothing就可以了,但是没有成功。我试过这个方法。
self.save = function() {
cartLine([])
var dataToSave = $.map(self.lines(), function(line) {
return line.product() ? {
productName: line.product().name,
quantity: line.quantity()
} : undefined
});
alert("THANK YOU FOR YOUR ORDER!");
};
但是没有用 如果我说的不对,请纠正我。谢谢。
更新:我正在尝试使用knockout js的例子。
self.save = function() {
var dataToSave = $.map(self.lines(), function(line) {
return line.product() ? {
productName: line.product().name,
quantity: line.quantity()
} : undefined
});
self.lines([]);
self.addLine = function() { self.lines.push(new CartLine()) };
alert("THANK YOU FOR YOUR ORDER!");
self.addLine = function() { self.lines.push(new CartLine()) }; //didn't work
};
该 lines
的领域 Cart
对象包含所有的购物车线。它用于生成 dataToSave
,然后你就可以清除它。
self.save = function() {
var dataToSave = $.map(self.lines(), function(line) {
return line.product() ? {
productName: line.product().name,
quantity: line.quantity()
} : undefined
});
self.lines([]); // clear cart lines
alert("THANK YOU FOR YOUR ORDER!");
self.addLine(); // add a new line