javascript - 在不调用 read() 的情况下设置剑道数据源

标签 javascript jquery listview kendo-ui

是否可以在没有 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/

相关文章:

javascript - AngularJs - 使用 ng-init 时遇到问题

jquery - ruby on Rails - 如何使用ajax读取json文件?

android - 滚动时ListView背景变黑

java - 如何显示上一个和下一个列表项的详细信息

javascript - 如何在 IE 中通过 src 属性隐藏图像?

javascript - Lodash pickAs - 在不同的键下从对象中选择属性到新对象中

javascript - 如何附加 Html.Action 以使用 javascript 查看

Ajax(jQuery)跨域输出——

javascript - 当加载的图像大于 div 时

android - Youtube 播放列表到 Android Studio 中的 ListView