我有多个网格,我想在一个提交按钮下运行。 以下是代码:http://jsfiddle.net/aETvS/
我收到错误“无法读取属性'推送'未定义”
self.orders = ko.observableArray(orders);
self.addorder = function() {
self.orders.push({
name: "",
price: ""
});
};
self.removeorder = function(order) {
self.orders.remove(order);
};
self.hardware = ko.observableArray(hardware);
self.addhardware = function() {
self.hardware.push({
name: "",
price: ""
});
};
self.removehardware = function(hardware) {
self.hardware.remove(hardware);
};
self.save = function(form) {
alert("Could now transmit to server: " + ko.utils.stringifyJson(self.orders));
// To actually transmit to server as a regular form post, write this: ko.utils.postJson($("form")[0], self.orders);
};
答案 0 :(得分:0)
您想发布表单。向表单添加提交绑定。
data-bind =“submit:save”
我已经更新了你的小提琴。但是我没有看到数组推送出错。
http://jsfiddle.net/sujesharukil/qMDH5/19/
<form class="form-horizontal margin-zero" method="POST" action="http://toolkit.dev/" accept-charset="utf-8" novalidate="novalidate" data-bind="submit: save">
希望有所帮助。
-Suj