【问题标题】:Kendo DropDownList requestEnd push value undefinedKendo DropDownList requestEnd 推送值 undefined
【发布时间】:2015-05-13 17:16:07
【问题描述】:

我有一个通过 data- 属性初始化的 DropDownList。我需要向列表中添加一个项目,但在我推送新选项后,我使用的代码将值显示为“未定义”。

这是我使用 data- 属性的元素(工作正常):

 <select id="#people_list"
     name="person_id"
     class="form-control"
     data-role="dropdownlist"
     data-source="datasource_people"
     data-option-label="Select A Name"
     data-auto-bind="true"
     data-text-field="name"
     data-value-Field="name"
     data-ignore-case="true"
     data-filter="startswith"
     >
     </select>

这是我的数据源参数(工作正常):

datasource_people = new kendo.data.DataSource({
        type: "json",
        serverFiltering: true,
        transport: {
            read: {
                dataType: 'json',
                type: 'GET',
                url: '/restful/people/'
            }
        },
        filter: {
            field: "status",
            operator: "eq",
            value: 1
        },
        schema: {
            data: function(response) {
                return response.data.people;
            },
            model: {
                id: "person_id",
                fields: {
                    person_id: {type: "number"},
                    name: { type: "string"}
                }
            },
            errors: "error",
            total: function(response) {
                return response.data.total;
            }
        }
    });

然后稍后(不起作用 - 将新项目添加为“未定义”):

$("#people_list").kendoDropDownList({
    dataTextField: "text",
    dataValueField: "value",
    dataSource: {
        datasource_people,
        requestEnd: function (e) {
            e.response.push({text: "John", value: "John"});
        }
    }
});

【问题讨论】:

  • 可能是dataTextField和dataValueField不对?

标签: jquery kendo-ui kendo-dropdown


【解决方案1】:

查看了一些文档以了解其他方法,这非常有效。

$("#people_list").getKendoDropDownList().dataSource.insert({
    person_id: "John",
    name: "John"
})

谢谢

【讨论】:

    【解决方案2】:

    你应该像这样定义数据源的请求结束事件,而不是把它放在你的 DropDownList 的启动代码中

    var dataSource = new kendo.data.DataSource({
      transport: {
        read: {
          url: "http://demos.telerik.com/kendo-ui/service/products",
          dataType: "jsonp"
        }
      },
      requestEnd: function(e) {
        var response = e.response;
        var type = e.type;
      }
    });
    

    【讨论】:

      猜你喜欢
      • 2021-11-18
      • 1970-01-01
      • 1970-01-01
      • 2014-10-05
      • 1970-01-01
      • 2013-08-30
      • 1970-01-01
      • 1970-01-01
      • 2014-03-28
      相关资源
      最近更新 更多