2
我已经定义了一个剑术数据源与传输方法(创建,读取,更新和破坏),以及一模式定义:剑道MVVM绑定添加/插入项目,如何?
$(document).ready(function() {
var viewModel = kendo.observable({
dsMedication: new kendo.data.DataSource({
type: "json",
serverFiltering: true,
serverPaging: true,
pageSize: 6,
error: function(e) {
//alert(e.responseText);
//var error_obj = $.parseJSON(e.responseText);
//if (error_obj.Message != null) {
//alert(error_obj.Message);
//}
},
transport: {
read: {
contentType: "application/json; charset=utf-8",
type: "POST",
url: "../Services/svcMedication.asmx/SearchMedication",
dataType: "json",
cache: false
},
update: {
contentType: "application/json; charset=utf-8",
type: "POST",
url: "../Services/svcMedication.asmx/SaveMedication",
dataType: "json",
cache: false
},
destroy: {
url: "../Services/svcMedication.asmx/DeleteMedication",
type: "DELETE",
dataType: "json",
cache: false
},
create: {
contentType: "application/json; charset=utf-8",
type: "POST",
url: "../Services/svcMedication.asmx/SaveMedication",
cache: false
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return kendo.stringify({ models: options.models });
}
options.MedicationParam = $('#acMedications').val();
return kendo.stringify(options);
}
},
batch: true,
schema: {
data: "d",
model: {
id: "MedicationId",
fields: {
MedicationId: {
type: "number",
editable: false // this field is not editable
},
Name: {
type: "text",
validation: { // validation rules
required: true // the field is required
}
}
}
}
}
}),
SelectedMedication: null,
HasChanges: false,
save: function() {
//if (this.SelectedMedication == null) {
//this.dsMedication.add({ MedicationId: this.get("MedicationId"), Name: this.get("Name") });
//}
this.dsMedication.sync();
this.set("HasChanges", false);
},
remove: function() {
if (confirm("Are you sure you want to delete this record?")) {
this.dsMedication.remove(this.SelectedMedication);
this.set("SelectedMedication", this.dsMedication.view()[0]);
this.change();
}
},
showForm: function() {
return this.get("SelectedMedication") !== null;
},
change: function() {
this.set("HasChanges", true);
}
});
kendo.bind($("#fmMedication"), viewModel);
});
我的形式元素包含适当的数据绑定的属性,以形成元件,并且我打电话给kendo.bind传递表单。目标是表格用于加和编辑记录。
如果我搜索一个项目并对其进行更改,那么每件事都像一个魅力!
我的问题是:
我不知道如何编写代码来初始化形式增加新记录的数据源。
我一直在找不到任何地方的例子或资源!
任何帮助,将不胜感激!谢谢!
在我的问题datasource hasbeen更新,但值不去创建操作或网格self.dsProduct.add(vm_Currencies.selectedRow);我已经声明模型seperatly,也做了视图模型的功能我应该怎么做创建操作被称为 – 2015-06-26 09:34:26
你指定了datasource.schema.model配置中的model.id字段? – 2015-06-26 21:27:57
我必须在添加到我的数据源之前将数据上的model.id设置为零,然后才能实际调用create方法。 – ooXei1sh 2017-08-22 17:45:08