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

时间:2014-04-10 07:30:15

标签: kendo-ui kendo-grid

我正在尝试使用编辑命令链接来编辑一行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未定义。任何相同的线索。

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:0)

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

相关问题