【问题标题】:assigning variable to kendo ui filter将变量分配给 kendo ui 过滤器
【发布时间】:2018-03-07 16:21:51
【问题描述】:

我无法将变量分配给数据源过滤器。我错过了什么?

var selectVal = "测试";

    var wcDataSource = new kendo.data.DataSource({
        transport : { read : function(data) {
            $http.get(restUrls.GET_OPR
                    .replace('?', '100')
                    .replace('?', '251')
                    .replace('?', '211'))
            .then(function(response) {  
                data.success(response.data.workCenter); 
                console.log("selected value:  "+selectVal); //outputs 'Test'
            }, function(error) {
                swal("Error!", "Error while fetching!", "error");
            });
            }
        },
        filter: {
            filters: [
                {field: "cc", operator: "eq", value: selectVal} // selectVal doesn't read here
            ]
        }
    });

请任何人告诉我,我在这里缺少什么。谢谢。

【问题讨论】:

    标签: kendo-ui


    【解决方案1】:

    如果您想接收必须启用的过滤器 serverFiltering:在您的数据源选项中为 true。

    这将为您提供 options.data 属性中的过滤器:)

      var dataSource = kendo.data.DataSource.create({
            transport: {
                read: function(options) {
                    $.ajax({
                        type: 'POST',
                        contentType: 'application/json',
                        dataType: 'json',
                        url: '/read',
                        data: options.data,
                        success: function(result) {
                            options.success(result);
                        },
                        error: function(xhr) {
                            // do what you want.
                        }
                    });
                }
            },
            serverFiltering: true, //<-- important
            filter: {
                filters: [{
                    operator: 'eq',
                    field: 'Name',
                    value: 'David'
                }]
            }
        });
    
        dataSource.read();
    

    【讨论】:

    • 嗨大卫,很抱歉延迟回复。非常感谢您提供的解决方案。
    • 如果它回答了您的问题,请标记为答案:)
    猜你喜欢
    • 1970-01-01
    • 2022-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 2021-09-19
    • 1970-01-01
    相关资源
    最近更新 更多