是否可以在没有 DataSource 的情况下设置 Kendo ListView 的 DataSource 然后调用 read()
方法?
我有一个在 ListView 和所有子 ListView 上使用的主数据源,但我只是根据一些条件为每个 ListView 过滤它。我这样做的方式是,一旦所有数据都绑定(bind)到主 ListView,然后我创建所有子 ListView 并分配具有过滤功能的相同数据源。
我在这里遇到的问题是,一旦我将过滤后的数据源分配给新的 ListView,它似乎又在调用读取方法。
baSurveyGroupTemplateDataSource: new kendo.data.DataSource({
transport: {
read: {
async: false,
url: "/Url/to/data"
dataType: "json",
type: "GET",
data: {
id: $("#TemplateId").val()
},
}
}
}),
groupDataBound: function (e) {
$(".childBaSuveyGroupTemplate").each(function () {
viewModel.seedGroup(this);
});
},
seedGroup: function (parentGroup) {
var childrenGroupList = $(parentGroup);
var parentGroupId = childrenGroupList.data("id");
var childrenGroupDataSource = new kendo.data.DataSource(viewModel.baSurveyGroupTemplateDataSource);
childrenGroupDataSource.query({
filter: ({ field: "BaSurveyGroupTemplateParentId", operator: "eq", value: parentGroupId })
});
childrenGroupList.kendoListView({
template: kendo.template($("#baSurveyGroupTemplateDisplayTemplate").html()),
dataSource: childrenGroupDataSource
});
}
如果我需要澄清任何事情,请告诉我。很难尝试用语言表达我正在做的事情和遇到的问题。
最佳答案
尝试将此添加到您的 ListView 配置中:
autoBind: false
来自 http://docs.telerik.com/kendo-ui/api/javascript/ui/listview#configuration-autoBind 的剑道文档
If set to false the widget will not bind to the data source during initialization. In this case data binding will occur when the change event of the data source is fired. By default the widget will bind to the data source specified in the configuration.
Setting autoBind to false is useful when multiple widgets are bound to the same data source. Disabling automatic binding ensures that the shared data source does not make more than one request to the remote service.
然后在设置好所有内容后手动触发数据源读取:
childrenGroupDataSource.read(); // "read()" will fire the "change" event of the dataSource and the widget will be bound
关于javascript - 在不调用 read() 的情况下设置剑道数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43122469/