我有一个问题,我为我的外键字段使用下拉列表,如演示:http ://demos.kendoui.com/web/grid/foreignkeycolumn.html
不同之处在于,如果我的模型中的外键字段与其他任何人都不相关,则有时它可能为空。然后我的问题是,当我尝试用这个外键字段的原始值为 null 来编辑行时,我想更改为另一个值,这个字段总是会得到值'[object object]'。我不知道为什么。
请参阅以下代码中的 floor 字段:
<script>
$(document).ready(function() {
var template = kendo.template($("#detail_template").html());
function show_menu_details(menuObj) {
var tg = $("#details");
tg.fadeOut(function(){
tg.html(template(menuObj));
tw = tg.find(".k-window");
tw.css({width:tg.innerWidth()-30, height:tg.innerHeight()-55, "margin-top": 20, "margin-left":15});
});
tg.fadeIn();
}
$("#horizontal").kendoSplitter({
panes: [{collapsible: true, size: "180px"},
{ collapsible: true} ],
height: 690
});
function onChange(e){
e.preventDefault();
selectedObj = this.dataSource.getByUid(this.select().data('uid'))
//console.log(selectedObj);//(this.dataSource.data());
show_menu_details(selectedObj);
}
var statuses = [
{value:'', text:'--'},
{value:'Available', text:'Available'},
{value:'Locked', text:'Locked'},
{value:'Reserved', text:'Reserved'},
{value:'Occupied', text:'Occupied'}];
var floors = new Array();
floors[0]={text:'--',value:''};
_DS_Floor.fetch(function(data){
$.each(data.items,function(index,obj){
floors[index+1] = {text: obj.name, value: obj.id};
});
var grid = $("#list").kendoGrid({
dataSource: _DS_Room,
selectable: "row",
filterable: true,
columnMenu: true,
pageable: {refresh:true},
editable: {mode:"popup",confirmation:"Sure to delete?"},
height: 688,
scrollable: {
virtual: true
},
sortable: true,
toolbar: kendo.template($("#toolbar_template").html()),
columns: [//{field:'id',title:' ',width:40,template: '<input type="checkbox" id="#= id #" />'},
{field:'name',title:'Name'},
{field:'floor',title:'Floor',values:floors},
{field:'position',title:'Position'},
{field:'status',title:'Status',width:80,values:statuses}],//_Columns_Menu,//{ command: ['edit','destroy'], title: "", width: "200px" }
//change: onChange
});
grid.find("#btn-add").click(function(e){
e.preventDefault();
grid.data("kendoGrid").addRow();
});
grid.find("#btn-save").click(function(e){
e.preventDefault();
grid.data("kendoGrid").saveChanges();//editRow(grid.data("kendoGrid").select());
});
grid.find("#btn-remove").click(function(e){
e.preventDefault();
grid.data("kendoGrid").removeRow(grid.data("kendoGrid").select());
});
grid.find("#btn-cancel").click(function(e){
e.preventDefault();
grid.data("kendoGrid").cancelChanges();//removeRow(grid.data("kendoGrid").select());
});
});
});
</script>
谢谢。