Kendo ui 剑道下拉列表默认选定项

Kendo ui 剑道下拉列表默认选定项,kendo-ui,kendo-asp.net-mvc,Kendo Ui,Kendo Asp.net Mvc,我在一个 var remainingfallities=[ {“文本”:“设施1”,“价值”:“1”}, {“文本”:“设施2”,“价值”:“2”}, {“文本”:“设施3”,“价值”:“3”}, {“文本”:“设施4”,“价值”:“4”}, {“文本”:“贷款5”,“价值”:“5”}, {“文本”:“设施6”,“价值”:“6”}, {“文本”:“贷款7”,“价值”:“7”}, ]; var ds=新的kendo.data.DataSource({ 数据:剩余错误 }); var sele

我在一个

var remainingfallities=[
{“文本”:“设施1”,“价值”:“1”},
{“文本”:“设施2”,“价值”:“2”},
{“文本”:“设施3”,“价值”:“3”},
{“文本”:“设施4”,“价值”:“4”},
{“文本”:“贷款5”,“价值”:“5”},
{“文本”:“设施6”,“价值”:“6”},
{“文本”:“贷款7”,“价值”:“7”},
];  
var ds=新的kendo.data.DataSource({
数据:剩余错误
});
var selectedFacilities=[
{“文本”:“贷款8”,“价值”:“8”},
{“文本”:“设施9”,“价值”:“9”}];
var dataSource=new kendo.data.dataSource({
数据:选定的设施,
批次:假,
页面大小:20,
模式:{
型号:{
id:“值”,
字段:{Text:{type:“string”}
}
}
});        
$(“#设施网格”).kendoGrid({
数据源:数据源,
自动绑定:是的,
可编辑:{mode:“inline”},
可排序:是的,
是的,
工具栏:[“创建”],
栏目:[
{命令:[“销毁”、“编辑”],标题:,宽度:“250px”},
{字段:“文本”,标题:“设施名称”,编辑:FacilitHydropowneditor},
]
});
函数facilithydropowneditor(容器,选项){
$('')
.appendTo(容器)
.kendoDropDownList({
自动绑定:是的,
数据源:ds
});
}
问题是,当用户单击“添加新记录”时,它会添加一个新项目,其中设施名称下拉列表显示列表中的第一个项目。如果用户单击“更新”,则会保存记录,但会将设施名称清空。原因是,下拉列表中确实没有选定项目。我之所以知道这一点,是因为所选值在传递给控制器代码时为空。所以,我真的很想知道如何

  • 在用户在列表中实际选择前,不显示列表中的第一项,或
  • 将所选项目设置为列表中的第一个项目,以便在传递给我的控制器时该值不会为null

  • 两种方法的答案都会更好。

    您的建议中没有列出的一个选项是设置
    optionLabel
    ,当值为
    null
    时显示该选项

    $('<input required data-text-field="Text" data-value-field="Value" data-bind="value: Text"/>')
        .appendTo(container)
        .kendoDropDownList(
        {
            autoBind: true,
            dataSource: ds,
            optionLabel:"Select Facility"
        }
    );
    
    $(“”)
    .appendTo(容器)
    .kendoDropDownList(
    {
    自动绑定:是的,
    数据源:ds,
    选项标签:“选择设施”
    }
    );
    

    您的jsiddle-modified一个选项未列在您的提案中,它是设置
    选项标签
    ,该标签在值为
    null
    时显示

    $('<input required data-text-field="Text" data-value-field="Value" data-bind="value: Text"/>')
        .appendTo(container)
        .kendoDropDownList(
        {
            autoBind: true,
            dataSource: ds,
            optionLabel:"Select Facility"
        }
    );
    
    $(“”)
    .appendTo(容器)
    .kendoDropDownList(
    {
    自动绑定:是的,
    数据源:ds,
    选项标签:“选择设施”
    }
    );
    

    您的JSFIDLE修改为在用户手动选择下拉列表项之前不显示下拉列表项。请使用
    optionLabel

    function facilityDropDownEditor(container, options) {            
            $('<input required data-text-field="Text" data-value-field="Value" data-bind="value: Text"/>')
                .appendTo(container)
                .kendoDropDownList({
                    autoBind: true,
                    dataSource: ds,
                    optionLabel: "Select an item..."
                });
        }
    

    要在用户手动选择之前不显示下拉列表的项目,请使用
    optionLabel

    function facilityDropDownEditor(container, options) {            
            $('<input required data-text-field="Text" data-value-field="Value" data-bind="value: Text"/>')
                .appendTo(container)
                .kendoDropDownList({
                    autoBind: true,
                    dataSource: ds,
                    optionLabel: "Select an item..."
                });
        }