我是剑道新手,几天后我试图弄清楚如何用搜索数据填充剑道网格。我的情况如下:
我有 javascript 视图模型:
sl.kendo = function () {
var billingReportViewModel = kendo.observable({
billingReportCriteria: [],
executeSearch: function (e) {
var $grid = $("#gridResults").data("kendoGrid");
$grid.dataSource.read();
$grid.refresh();
}
});
return {
billingReportViewModel: billingReportViewModel
}
} ();
我用这个函数从服务器初始化 billingReportCriteria:
var initCriteriaViewModel = function () {
$.ajax({
url: 'GetBillingReportCriteria',
type: "GET",
dataType: "json",
success: function (model) {
**$.extend(sl.kendo.billingReportViewModel.get("billingReportCriteria"), kendo.observable(model));**
// bind to the viewModel
kendo.bind($("#searchTable"), sl.kendo.billingReportViewModel);
}
});
}()
比我声明将这个 billingReportCriteria 作为参数发送到服务器的网格数据源:
var gridDataSource = new kendo.data.DataSource({
transport: {
read: {
url: "GetBillingReportResults",
data: JSON.stringify(sl.kendo.billingReportViewModel.get("billingReportCriteria")),
cache: false,
type: "POST"
}
},
schema: {
data: "Items",
total: 10 // total number of data items is returned in the "count" field of the response
}
});
我初始化我的剑道网格:
$("#gridResults").kendoGrid({
columns: [
{
field: "Name"
},
{
field: "Title"
}],
dataSource: gridDataSource,
autoBind: false
});
当我从视图模型“executeSearch”执行搜索时,我转到服务器,但 billingReportCriteria 为空!当我从 F12 Chrome 工具中检查 'billingReportViewModel' 值时,一切似乎都正常,但是当我检查 'sl.kendo.billingReportViewModel.billingReportCriteria' 或 'sl.kendo.billingReportViewModel.get("billingReportCriteria")' 的值时 -它是空的,尽管 'sl.kendo.billingReportViewModel.get("billingReportCriteria.Name")' 例如具有正确的值!你能建议问题是什么吗?不知何故,我无法将正确的“billingReportCriteria”发送到服务器!