Kendo DataSource:如何在不发送两个 httprequest 的情况下在获取之前设置过滤器 [英] Kendo DataSource: How to set filters before fetch without sending two httprequests

查看:13
本文介绍了Kendo DataSource:如何在不发送两个 httprequest 的情况下在获取之前设置过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境:

  • 剑道版本:2013.1.319
  • 数据源:

  • kendo version: 2013.1.319
  • dataSource:

productsDataSource = new kendo.data.DataSource({
    type: "odata",
    transport: {
        read: "http://www.mydomain.com/odata.svc/products",
        dataType: "json",
        contentType: "application/json"
    }
    schema: {
        type: "json",
        data: function(data){
            return data.value;
        },
        total: function(data){
            return data['odata.count'];
        },
        model: product
    },
    pageSize: 50,
    serverPaging: true,
    serverFiltering: true,
    serverSorting: true
});

  • 获取数据:

  • Get data:

    productsDataSource.filter([{ field: "Id", operator: "eq", value: 5 }]);//这将发送一个http请求

    productsDataSource.filter([{ field: "Id", operator: "eq", value: 5 }]); //this will send an httprequest

    productsDataSource.fetch(function (e) {tempDataStorage = e.items;//处理数据的更多逻辑;});

    productsDataSource.fetch(function (e) { tempDataStorage = e.items; //more logic to dealing with the data; });

    问题:

    1. 需要使用dataSource的fetch方法进行数据处理(widgets初始化、数据绑定等);
    2. 在获取之前设置过滤器时避免发送两个http请求;
    3. 需要在运行时更改过滤条件.

  • 推荐答案

    productsDataSource._filter = { logic: 'and', filters: [
    { field: "Id", operator: "eq", value: 5 }]};
    

    我发现这行得通.将内部属性设置为完整的过滤器对象.然后您可以在之后调用 fetch.但是,我还没有找到一种在不触发提取的情况下更改页面大小的方法.

    I've found this to work. Set the internal property to a full filter object. You can then call fetch afterwards. I've not yet found a way to change the page size without triggering a fetch however.

    这篇关于Kendo DataSource:如何在不发送两个 httprequest 的情况下在获取之前设置过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆