【问题标题】:Kendo UI Grid. DropDown does not show the pre-selected value as default剑道用户界面网格。 DropDown 不显示预选值作为默认值
【发布时间】:2018-03-23 15:27:15
【问题描述】:

首先,我要为我拙劣的英语道歉。

我目前正在试验剑道 UI,更具体地说是网格。

我有列“id”、“event”、“database”、“address”和“eventtype”(简化)。

columns: [
{field: "id", hidden: true},
{field: "event", hidden: false, title: "Event"},
{field: "database", hidden: false, title: "Database", width: 100},
{field: "address", hidden: false, title: "Address", width: 100},
{field: "eventtype", hidden: false, title: "Event Type", editor: eventtypeDropDownEditor},
{command: ["destroy", "edit"],  hidden: false, width: 200}],

除了eventtype,所有这些都是常见的文本输入和按钮。事件类型存储在单独的表中(id 和 eventtype(string))。

eventtypeDropDownEditor如下

 function eventtypeDropDownEditor(container, options) {
$('<input data-text-field="eventtype" data-value-field:"id" data-bind="value:' + options.field+ '"/>')
    .appendTo(container)
    .kendoDropDownList ({
        autoBind: false,
        dataTextField: "eventtype",
        dataValueField:"id",
        dataSource: {
            transport: {
                read: "https://some.url/default/ajax/geteventtype",
                dataType: "json"
            }
        },
    });

};

被调用的 dataSource URL 传递一个类似 JSON 的格式

[{"id":"0","eventtype":"placeholder0"},{"id":"1","eventtype":"placeholder1"},{"id":"2","eventtype":"placeholder2"},{"id":"6","eventtype":"placeholder3"}]

到目前为止,一切都很好。编辑、删除、创建工作完美。

我唯一的问题(现在 6 小时)是在启用编辑后在我的列 eventtype 中显示相应的事件类型。

换句话说:如果我单击“编辑”按钮,eventtype“placeholder1”下显示的文本将变为下拉菜单。但不是预先选择“placeholder1”,下拉菜单是空的。我必须手动单击下拉菜单并选择其中一个选项。例如,即使我只想更改数据库,我也总是必须选择一个事件类型才能为我的查询提供有效值。

在测试不同的解决方案时,我偶然发现了index 选项。奇怪的是,这个也不起作用。也不会更改 data-bind 值。

我猜这是某种“更大”的错误,阻止了任何类型的选项按预期在该上下文中工作。但我根本找不到进一步调查的解决方案或“方向”。

我真的很感激这个问题的解决方案或“提示”!

问候 马塞尔

【问题讨论】:

  • 您是否尝试将autoBind 设置为true
  • @SteveGreene 由文档 valuePrimitve 描述听起来完全像我可能需要的。遗憾的是,我要到下周一才能尝试。
  • @Supersnake 我很遗憾已经尝试更改自动绑定设置。
  • @SteveGreene 设置valuePrimitive 选项也没有影响。很遗憾。

标签: javascript kendo-ui kendo-grid dropdownbox


【解决方案1】:

我猜问题是data-bind="value=' + options.field+ '" 中的等号。

尝试更改为data-bind="value:' + options.field+ '"

【讨论】:

  • Ups,这是我在修改 stackoverflow 代码时犯的错误。这是你提到的一点的双重点。
【解决方案2】:

我找到了解决方案。 我不必在字段定义中调用函数eventtypeDropDownEditor,而是直接在其中定义编辑器。

    {field: "eventtype", title: "Event Type",
    editor: function(container) {
        var input = $('<select id="eventtype" name="eventtype">');
        input.appendTo(container);
        input.kendoDropDownList({
            dataTextField: "eventtype",
            dataValueField: "eventtype",
            dataSource: {
                transport: {
                    read: "https://some.url/default/ajax/geteventtype",
                    dataType: "json"
                }
            }
        }).appendTo(container);
    }
},

【讨论】:

    猜你喜欢
    • 2019-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多