我的表单无法更新从服务器获取的数据到表单的记录。下面是我的 w2form
$().w2form({
name: 'editSv',
method: 'GET',
style: 'border: 0px; background-color: transparent;',
recid: w2ui['grid'].records[w2ui['grid'].getSelection(true)]['id'],
url: {
get: '/api/Test/GetService/' + w2ui['grid'].records[w2ui['grid'].getSelection(true)]['id'],
save: '/api/Test/PostService'
},
formURL: '/api/Test/GetService/' + w2ui['grid'].records[w2ui['grid'].getSelection(true)]['id'],
fields: [
{ name: 'id', type: 'number', required: true },
{ name: 'servicename', type: 'text', required: true },
{ name: 'price', type: 'number', required: true },
{ name: 'unit', type: 'text' }
],
record: {
id: 0,
servicename: '',
price: 0,
unit: ''
}, onSubmit: function (formName, formObj) {
formObj.postData = formObj.postData.record;
},
onLoad: function (event) {
console.log(event.xhr);
},
actions: {
"save": function () {
var obj = this;
this.submit({}, function (data) {
if (data.status == 'success') {
w2alert(data.status);
w2ui['grid'].reload();
} else {
w2alert(data.message);
return;
}
obj.clear();
});
},
"reset": function () { this.clear(); },
}
});
这是从 onLoad() 事件获得的数据
{readyState: 4, responseText: "{"id":5,"servicename":"4","price":4.0000,"unit":"4"}", status: 200, statusText: "OK"}
来自 chrome 控制台的消息:
ERROR: Cannot associate field "id" with html control. Make sure html control exists with the same name.
ERROR: Cannot associate field "servicename" with html control. Make sure html control exists with the same name.
ERROR: Cannot associate field "price" with html control. Make sure html control exists with the same name.
ERROR: Cannot associate field "unit" with html control. Make sure html control exists with the same name.
我曾尝试将 formHTML 添加到 w2form,但这没有任何意义。有没有人解决过这个问题?