Kendo Ui kendoDropDownList模板文本未显示

时间:2015-08-18 11:45:35

标签: kendo-ui

我在网格上有一个kendoDropDownList列,但我无法获取要显示的项目的文本。它不断显示价值!

          var sexes = [{ "Text": "Male", "Code": "M" }, { "Text": "Female", "Code": "F" }];

          function sexDropDownEditor(container, options) {

                    $('<input required data-value-field="Code" data-text-field="Text" data-bind="value:' + options.field + '"/>')
                    .appendTo(container)
                    .kendoDropDownList({
                        dataTextField: "Text",
                        dataValueField: "Code",
                        dataSource: sexes,
                        template: "#=data.Text#"
                    });
           }

           $("#grid").kendoGrid({
                dataSource: dataSource,
                pageable: true,
                selectable: "row",
                filterable: true,
                sortable: true,
                height: 275,
                toolbar: ["create"],
                columns: [
                    ....
                    { field: "Sex", title: "Sex", editor: sexDropDownEditor }
                    ....
                    { command: ["edit", "destroy"], title: "&nbsp;", width: "250px" }],
                editable: "inline"
            });

当未编辑行时,我希望显示所选项目的文本,但由于某种原因,它会显示该值。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

通过向网格列添加模板对此进行排序(类似于Robin Giltner的建议)

<script id="sexTemplate" type="text/x-kendo-template">

       #if (Sex !== null) {#
            #= Sex === 'M' ? 'Male' : 'Female' #
       #}#

</script>

 { field: "Sex", title: "Sex", editor: sexDropDownEditor, template: kendo.template($("#sexTemplate").html()) },