我有一个带有两个多选小部件的视图,其值(region_edu_admin,edu_admin)和数据源(region_edu_admins_ds,edu_admins_ds)被绑定(通过数据绑定)到ViewModel。在region_edu_admin的更改事件(regionEduAdminChanged)中,我试图通过使用set方法重新加载edu_admin的小部件数据源,即edu_admins_ds。虽然我确实进入newEduAdminsDS(),但数据源不会重新加载。关于我是什么的任何想法我在这里失踪将非常感激!您可以看到以下代码:
/ *查看模型* /
var LabsSearchVM = kendo.observable({
region_edu_admins_ds: newRegionEduAdminsDS(),
edu_admins_ds: newEduAdminsDS(),
region_edu_admin: "",
edu_admin: "",
regionEduAdminChanged: function(e) {
this.set("edu_admins_ds", newEduAdminsDS());
}
});
/ *查看* /
<label for="region_edu_admin">Περιφερειακή Διεύθυνση Εκπαίδευσης</label>
<select id="sl_region_edu_admin"
name="region_edu_admin"
data-role="multiselect"
data-auto-bind="false"
data-value-primitive="true"
data-text-field="name"
data-value-field="name"
data-bind="source: region_edu_admins_ds, value: region_edu_admin, events: {change : regionEduAdminChanged }"
data-filter="contains"
multiple="multiple">
</select>
<label for="edu_admin">Διεύθυνση Εκπαίδευσης</label>
<select id="sl_edu_admin"
name="edu_admin"
data-role="multiselect"
data-auto-bind="false"
data-text-field="name"
data-value-field="name"
data-bind="source: edu_admins_ds, value: edu_admin"
data-filter="contains"
multiple="multiple">
</select>
/ * newEduAdminsDS()函数* /
function newEduAdminsDS() {
var edu_admins_ds = new kendo.data.DataSource({
transport: {
read: {
url: "api/edu_admins",
type: "GET",
dataType: "json"
}
},
schema: {
data: "data",
model: {
id: "edu_admin_id",
fields: {
edu_admin_id: { editable: false },
name: { editable: false },
region_edu_admin_id: { editable: false },
region_edu_admin: { editable: false }
}
}
}
});
return edu_admins_ds;
}
答案 0 :(得分:1)
您无需重新创建DataSource。您需要做的就是再次告诉read()
重新加载数据。将您的observable中的regionEduAdminChanged
函数更改为:
regionEduAdminChanged: function(e) {
this.edu_admins_ds.read();
}