【问题标题】:Drop-down in kendo-ui not retrieving datakendo-ui中的下拉菜单不检索数据
【发布时间】:2015-07-10 06:56:54
【问题描述】:

我正在做一个测试项目,我从 web api 填写下拉列表... 按原样使用ThisDemo....

这一切都运行良好,现在它一直显示控制台错误,我在问题结束时说过......

我确定只有定位模板有问题

{模板:“#=Status.StatusName#”}

...我不确定这是否是正确的方法....但是当我删除此代码部分错误消失但下拉显示未定义而不是 StatusName...

查看代码(我使用了选定的脚本)

...
    schema: {
        model: {
            id: "ProjectId",
            fields: {
                ProjectId: { editable: true, nullable: false, type: "number" },
                ClientId: { editable: true, nullable: false, type: "number" },
                Name: { editable: true, nullable: true, type: "string" },
               // Status: { editable: true, nullable: true, type: "string" },
               Status: { defaultValue: { StatusID: 1, StatusName: "Completed" } },
               IsActive: { editable: true, nullable: false, type: "boolean" },
            }
        }
    }
});

$("#grid").kendoGrid({
    dataSource: dataSource,
    pageable: true,
    toolbar: ["create"],
    scrollable: false,
    sortable: true,
    groupable: true,
    filterable: true,
    columns: [
        { field: "Name", title: "Project Name", width: "170px" },
        //{ field: "Status", title: "Status", width: "110px" },
        { field: "Status", title: "Status", width: "180px", editor: statusDropDownEditor, template: "#=Status.StatusName#" },
        { field: "IsActive", title: "Active", width: "50px" },
        { command: "", template: "<a href='Project/Task'>Manage Task</a>", width: "30px", filterable: false },
        { command: "", template: "<a href='Project/Setting'>Setting</a>", width: "30px", filterable: false },
        { command: ["edit", "delete"], title: "&nbsp;", width: "80px" }
    ],
    editable: "popup"
});

function statusDropDownEditor(container, options) {
    $('<input required data-text-field="StatusName" data-value-field="StatusID" data-bind="value:' + options.field + '"/>')
        .appendTo(container)
        .kendoDropDownList({
            autoBind: false,
            dataSource: {
                type: "odata",
                transport: {
                    read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Categories"
                }
            }
        });
}

未捕获的类型错误:无法读取属性“StatusName”的 空(匿名函数)@ VM1415:1pt.ui.DataBoundWidget.extend._rowsHtml @ kendo.all.min.js:31pt.ui.DataBoundWidget.extend._renderContent @ kendo.all.min.js:32pt.ui.DataBoundWidget.extend.refresh @ kendo.all.min.js:32b.extend.proxy.b.isFunction.i @ jquery.min.js:3i.extend.trigger@kendo.all.min.js:9ht.extend._process @ kendo.all.min.js:11ht.extend.success @ kendo.all.min.js:11ht.extend.read.n._queueRequest.n.online.n.transport.read.success @ kendo.all.min.js:11pt.extend.read.n.success @ kendo.all.min.js:11b.Callbacks.c @ jquery.min.js:3b.Callbacks.p.fireWith @ jquery.min.js:3k @ jquery.min.js:5b.ajaxTransport.send.r@jquery.min.js:5

如果有人有任何想法,请提供帮助,任何形式的帮助都将不胜感激,感谢您的宝贵时间

【问题讨论】:

    标签: javascript jquery ajax kendo-ui kendo-grid


    【解决方案1】:

    问题与 odata 服务返回的数据有关。数据如下所示:

    ProductID : 1,
    ProductName : "Chai",
    SupplierID : 1,
    CategoryID : 1,
    QuantityPerUnit : "10 boxes x 20 bags",
    UnitPrice : 18.0000,
    UnitsInStock : 39,
    UnitsOnOrder : 0,
    ReorderLevel : 10,
    Discontinued : false,
    Category : {
        CategoryID : 1,
        CategoryName : "Beverages",
        Description : "Soft drinks, coffees, teas, beers, and ales"
    }
    

    如您所见,odata 服务返回的数据中没有Status。缺少的字段(如Status)将被解析为undefined 值。但是,如果您尝试获取该 undefined 对象的属性(就像您的模板一样),最终会出现错误,因为您无法执行 undefined.undefined

    作为旁注; defaultValue 不受 kendo model 支持。

    【讨论】:

    • 感谢您的回答,非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-15
    • 1970-01-01
    • 2019-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多