繁体   English   中英

kendodropdownlist 过滤具有字段的 json 响应

[英]kendodropdownlist filter json response that has field

我目前正在做以下工作; 我所有的 JSON 条目都有styleName ,但是有些条目有字段txt ,我只想显示下拉列表中包含txt字段的styleName数据。

var dataSourceJSON = new kendo.data.DataSource({
    transport: {
        read: {
            url: dataURL,
            dataType: "json",
            type: 'GET'
        }
    }});dataSourceJSON.read();

    $("#dropdown").kendoDropDownList({
        dataSource    : dataSourceJSON,
        dataTextField : "styleName"
    });

使用剑道之前,我是用下面实现这个,内fetch经典的下拉列表。 但我不确定如何将这种逻辑与kendoDropDownList

if (data[i].txt) {
     option.text = data[i].styleName;
     dropdown.add(option);
}..../

更新,这是我目前所在的位置; 我可以在我的模式解析中console.log正确的数据,但仍然很难将过滤后的数据放入下拉列表中。

  var ctemp;
  var dataSourceJSON = new kendo.data.DataSource({
    transport: {
        read: {
            url: dataURL,
            dataType: "json",
            type: 'GET'
        }
    },
    schema: {
        parse: function(datC) {
            console.log(datC);
            for (let i = 0; i < datC.length; i++) {
                if (datC[i].txt) {
                    ctemp = datC; // <-- This works and what I need
                    console.log(ctemp);
                }
            }
        }
    }
    });dataSourceJSON.read();

    $("#dropdown").kendoDropDownList({
        optionLabel: "Choose",
        dataSource    : dataSourceC,
        dataTextField : ctemp // <--- does nothing
    });

在这种情况下,您可以使用 kendo dataSource过滤器。 数据源过滤器

只需检查一个字段是否为非空就可以了。

var dataSource = new kendo.data.DataSource({
  data: [
    { styleName: "Style 1", txt: 'test' },
    { styleName: "Style 2" },
    { styleName: "Style 3", txt: 'test' },
  ],
  filter: { field: "txt", operator: "isnotnull" }
});

我做了一个例子:按字段过滤

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM