我正在尝试实现 Cakephp kendo ui grid dropdownlist 来编辑列partner_type_id
但卡住了导致 dropdownlist populate [object][object]
。
这是我的代码:
$(function() {
var dataSource = new kendo.data.DataSource({
batch: true,
pageSize:10,
transport: {
read: {
url:"<?php echo $this->Html->url('/Partners/get_partner',true)?>",
dataType:"json",
}
},
schema: {
id:"Partner.id",
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
columns: [
{ field: "Partner.name"},
{ field: "Partner.partner_type_id",
template: "#: PartnerType.name #", editor: categoryDropDownEditor
},
{ command: ["edit"], title: " ", width: "182px" }
],
toolbar: ["create", "save", "cancel","destroy"],
height: 400,
navigatable: true,
pageable: {
refresh: true,
pageSizes:true
},
editable:"inline" ,
filterable: {
extra: false,
operators: {
string: {
startswith: "Starts with",
eq: "Is equal to",
neq: "Is not equal to"
}
}
},
});
function categoryDropDownEditor(container, options) {
$('<input required required data-text-field="PartnerType.name" data-value-field="Partner.id" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
dataSource: {
transport: {
read: {
url:"<?php echo $this->Html->url('/Partners/get_partner_type',true)?>",
dataType:"json",
}
},
},
});
}
});
如您所知,我使用嵌套的 JSON,有问题吗?我尝试使用具有相同代码的原生 PHP 和 MySql(平面 Json)并且运行良好。
/Partners/get_partner 返回如下: [ { "Partner":{"id":"1","name":"King James","partner_type_id":"2"}, "PartnerType":{"id":" 2","名称":"供应商"} } ]
/Partners/get_partner_type' 返回如下: [ {"PartnerType":{"id":"1","name":"Customer"}}, {"PartnerType":{"id":"2","name" :“小贩”}} ]
有人愿意分享吗?