KendoUI ComboBox 显示不正确的 REST JSON 解析

KendoUI ComboBox displaying incorrect parsing of REST JSON

本文关键字:REST JSON 解析 不正确 ComboBox 显示 KendoUI      更新时间:2023-09-26

我有一个宁静的服务响应{"SearchMode":["Customer","Address","Street","City"]},一切看起来都很好。我正在尝试将这些中的每一个作为选项添加到剑道组合框中。但是,它正在解析它并将每个字母显示为一个选项:

  • {
  • ">
  • S
  • e
  • 一个
  • r
  • C
  • h

你明白了。这是我在javascript中所做的工作。我正在学习剑道控件,因此非常感谢任何帮助。

$(#cboSearch").kendoComboBox({autobind:false, minLength:3, datasource:{type:json, serverFiltering: true, transport:{ read: { url: "http://myrestservicehere?f="}}} });

我知道我错过了一些明显的东西,并期待一些指导,谢谢。斯科特

DataSource定义中缺少说明返回对象中包含选项的数组的位置。这是使用 schema.data 完成的。它应该是:

$("#cboSearch").kendoComboBox({
    autoBind       : false,
    minLength      : 3,
    dataSource: new kendo.data.DataSource({
        serverFiltering: true,
        transport      : {
            read: {
                url: "http://myrestservicehere?f="
            }
        },
        schema         : {
            data: "SearchMode"
        }
    })
});

ComboBox 不支持绑定到字符串数组。您可以尝试将 JSON 更改为以下内容:

{
  "SearchMode": [
     {"text":"Customer"},
     {"text":"Address"},
     {"text":"Street"},
     {"text":"City"}
  ]
}

然后像这样配置组合框:

$("#cboSearch").kendoComboBox({
    autoBind       : false,
    minLength      : 3,
    dataTextField  : "text",
    dataValueField : "text",
    dataSource: new kendo.data.DataSource({
        serverFiltering: true,
        transport      : {
            read: {
                url: "http://myrestservicehere?f="
            }
        },
        schema         : {
            data: "SearchMode"
        }
    })
});