簡體   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