Kendo ui网格客户端模板“Id未定义”

问题描述 投票:3回答:2

我正在尝试使用编辑命令链接来编辑一行kendo web ui网格。问题是我无法使用语法“#= Id#”,Id被定义为模型中的id和其中一个字段。这是数据源中定义的模式

    var dataSource = new kendo.data.DataSource({
        type: "json",
        .....
        schema: {
            model: {
                id: "Id",
                fields: {
                    Id: { type: "number" },
                    RequesterName: { type: "string" },
                    ...
                }
            },
            data: "data",
            total: "total"
        },
        ...
        pageSize: 5
});

和剑道网格

$("#request-grid").kendoGrid({
    dataSource: dataSource,
    ...
    columns: [{
        field: "Id", title: "Id", width: 35
    }, {
        field: "RequesterName", title: "Req Name", width: 175
    }, { 
    ...
    }, {
        command: [{ name: "edit", template: "<a href='@Url.Action("_SoftwareRequestEdit", "SoftwareRequest")" + "/#= Id #" + "'>Edit</a>" }]
    }],
    ...
});

使用上面的代码,当网格加载时我得到以下javascript错误

ReferenceError: Id is not defined
#11 http://localhost:49713/Admin/SoftwareRequest/SoftwareRequestList:3
#10 http://localhost:49713/Scripts/Kendo/kendo.web.js:294:22 eval (eval at ()
#9 http://localhost:49713/Scripts/Kendo/kendo.web.js:26361:44 Widget.extend._createButton()
#8 http://localhost:49713/Scripts/Kendo/kendo.web.js:27571:38 Widget.extend._cellTmpl()
#7 http://localhost:49713/Scripts/Kendo/kendo.web.js:27523:41 Widget.extend._tmpl()
#6 http://localhost:49713/Scripts/Kendo/kendo.web.js:27624:37 Widget.extend._templates()
#5 http://localhost:49713/Scripts/Kendo/kendo.web.js:25055:18 new Widget.extend.init()
#4 http://localhost:49713/Scripts/Kendo/kendo.web.js:2785:25 HTMLDivElement.()
#3 http://localhost:49713/Scripts/jquery-2.1.0.js:381:23 Function.jQuery.extend.each()
#2 http://localhost:49713/Scripts/jquery-2.1.0.js:137:17 jQuery.fn.jQuery.each()
#1 http://localhost:49713/Scripts/Kendo/kendo.web.js:2784:26 $.fn.(anonymous function) [as kendoGrid]

如您所见,我在模型中定义了Id,但我仍然得到ReferenceError:Id未定义。任何相同的线索。

kendo-ui kendo-grid
2个回答
2
投票

模型中的变量只能用于模板列,而不能用于命令列。

基本上,您可以通过使用完整的template列来实现您的目标,您不必使用命令列。


0
投票

将“#= Id#”部分替换为“#= data.Id?Id:''#”

© www.soinside.com 2019 - 2024. All rights reserved.