I am doing the below currently; all my JSON entries have styleName
, however some have the field txt
, I want to display only the styleName
data that has the txt
field in my dropdown list.
var dataSourceJSON = new kendo.data.DataSource({
transport: {
read: {
url: dataURL,
dataType: "json",
type: 'GET'
}
}});dataSourceJSON.read();
$("#dropdown").kendoDropDownList({
dataSource : dataSourceJSON,
dataTextField : "styleName"
});
Before using kendo, I was achieving this with the below, within a fetch
on classic dropdowns. But I am unsure how to incorporate such logic with kendoDropDownList
if (data[i].txt) {
option.text = data[i].styleName;
dropdown.add(option);
}..../
Update , this is where I am currently at; I can console.log
the correct data in my schema parse but am still having a hard time getting the filtered data into the dropdown.
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
});
You can use kendo dataSource
filter for this case. DataSource filter
Just check if a field is notnull and that's it.
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" }
});
I made an example: Filter by field
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.