Javascript 剑道网格线编辑使用下拉列表编辑器(编辑自定义编辑器)
我正在使用上提供的示例Telerik在剑道UI网格中进行内联编辑,我想将内联下拉列表绑定到“类别”列中“创建一个JSON对象,而不是使用演示中的xml数据。当我使用JSON数据时,下拉列表不起作用。如何将JSON对象绑定到内联下拉列表 下面是绑定数据源的JavaScript函数Javascript 剑道网格线编辑使用下拉列表编辑器(编辑自定义编辑器),javascript,json,telerik,kendo-ui,kendo-grid,Javascript,Json,Telerik,Kendo Ui,Kendo Grid,我正在使用上提供的示例Telerik在剑道UI网格中进行内联编辑,我想将内联下拉列表绑定到“类别”列中“创建一个JSON对象,而不是使用演示中的xml数据。当我使用JSON数据时,下拉列表不起作用。如何将JSON对象绑定到内联下拉列表 下面是绑定数据源的JavaScript函数 function categoryDropDownEditor(container, options) { var categories = { 'Category': [
function categoryDropDownEditor(container, options) {
var categories = {
'Category': [
{ 'CategoryName': 'Beverages', 'CategoryID': 1 },
{ 'CategoryName': 'Condiments', 'CategoryID': 2 },
{ 'CategoryName': 'Confections', 'CategoryID': 3 },
{ 'CategoryName': 'Dairy Products', 'CategoryID': 4 },
{ 'CategoryName': 'Grains/Cereals', 'CategoryID': 5 },
{ 'CategoryName': 'Meat/Poultry', 'CategoryID': 6 },
{ 'CategoryName': 'Produce', 'CategoryID': 7 },
{ 'CategoryName': 'Seafood', 'CategoryID': 8 }
]
};
$('<input required data-text-field="CategoryName" data-value-field="CategoryID" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
dataSource: categories
});
}
function categorhydropdowneditor(容器、选项){
变量类别={
“类别”:[
{'CategoryName':'Beverages','CategoryID':1},
{“CategoryName”:“调味品”,“CategoryID”:2},
{'CategoryName':'糖果','CategoryID':3},
{'CategoryName':'Dairy Products','CategoryID':4},
{'CategoryName':'Grains/谷物','CategoryID':5},
{'CategoryName':'Meat/家禽','CategoryID':6},
{'CategoryName':'product','CategoryID':7},
{'CategoryName':'Seafood','CategoryID':8}
]
};
$('')
.appendTo(容器)
.kendoDropDownList({
自动绑定:错误,
数据源:类别
});
}
尝试更改以下内容
var Category =
[
{ 'CategoryName': 'Beverages', 'CategoryID': 1 },
{ 'CategoryName': 'Condiments', 'CategoryID': 2 },
{ 'CategoryName': 'Confections', 'CategoryID': 3 },
{ 'CategoryName': 'Dairy Products', 'CategoryID': 4 },
{ 'CategoryName': 'Grains/Cereals', 'CategoryID': 5 },
{ 'CategoryName': 'Meat/Poultry', 'CategoryID': 6 },
{ 'CategoryName': 'Produce', 'CategoryID': 7 },
{ 'CategoryName': 'Seafood', 'CategoryID': 8 }
];
作为数据源使用
$('<input required data-text-field="CategoryName" data-value-field="CategoryID" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
dataSource: Category
});
$(“”)
.appendTo(容器)
.kendoDropDownList({
自动绑定:错误,
数据源:类别
});
函数类别HydropDownEditor(容器,选项){
变量类别={
“类别”:[
{'CategoryName':'Beverages','CategoryID':1},
{“CategoryName”:“调味品”,“CategoryID”:2},
{'CategoryName':'糖果','CategoryID':3},
{'CategoryName':'Dairy Products','CategoryID':4},
{'CategoryName':'Grains/谷物','CategoryID':5},
{'CategoryName':'Meat/家禽','CategoryID':6},
{'CategoryName':'product','CategoryID':7},
{'CategoryName':'Seafood','CategoryID':8}
]
};
$('')
.appendTo(容器)
.kendoDropDownList({
自动绑定:错误,
数据源:categories.categories
});
}
综上所述,您需要使用属性绑定到数据源。因为kendo数据源需要一个数组对象
function categoryDropDownEditor(container, options) {
var categories = {
'Category': [
{ 'CategoryName': 'Beverages', 'CategoryID': 1 },
{ 'CategoryName': 'Condiments', 'CategoryID': 2 },
{ 'CategoryName': 'Confections', 'CategoryID': 3 },
{ 'CategoryName': 'Dairy Products', 'CategoryID': 4 },
{ 'CategoryName': 'Grains/Cereals', 'CategoryID': 5 },
{ 'CategoryName': 'Meat/Poultry', 'CategoryID': 6 },
{ 'CategoryName': 'Produce', 'CategoryID': 7 },
{ 'CategoryName': 'Seafood', 'CategoryID': 8 }
]
};
$('<input required data-text-field="CategoryName" data-value-field="CategoryID" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
dataSource: categories.Category
});
}