将变量从kendo数据源传递到模板

时间:2014-03-12 21:21:47

标签: kendo-ui kendo-grid

我正在尝试将一个字符串从kendo数据源传递到网格中的模板,该模板充当“打印”按钮。该按钮触发一个函数,打开一个到报表服务器的新链接,我需要将一个字符串值传递给该函数,以便在该URL中发送该字符串值。

如果我发送数据源Id字段,我可以使用它,但如果我尝试发送字符串值(Physician),我会收到“意外标识符”错误。我试过更改coluns:field:to Physician,但得到同样的错误。

编辑:我可以传递任何int值,但如果我尝试发送一个字符串就会中断。

如何将Id以外的值传递给我的模板?

    schema: {
        model: {
            id: "Id",
            fields: {
                "ClinicName": { type: "string" },
                "Physician": { type: "string" },
                "Phone": { type: "string" },
                "Fax": { type: "string" },
                "Specialty": { type: "string" },
                "Consent": { type: "date" }
            }
        }
    },
    pageSize: 10
});


function printForm(Physician) {
    var stuid = $('#sisid').html().match(/\d+/);
    var user = $('#user').val();
    var sid = $('#sess').val();
    window.open("http://@reportServer/ReportServer/Pages/ReportViewer.aspx?/SHPN/Treatment%20Form&rs:Command=Render&StudentId=" + stuid + "&SessionId=" + sid + "&CurrentUser=" + user + "&Physician=" + Physician);
};

$(document).ready(function () {

        columns: [
            {
                field: "Id",
                width: "38px",
                title: "Print",
                filterable: false,
                sortable: false,
                template: "<a class='change-image' href='javascript:void(0);' title='Print Treatment Form' onclick='printForm(#= Id #)'><img alt='Student Info' src='@Url.Content("~/Content/Images/printer-icon.png")' /></a>"
            },

2 个答案:

答案 0 :(得分:6)

由于Physicianstring,您可能无法正确转义它。尝试将模板定义为:

template: "<a class='change-image' href='javascript:void(0);' title='Print Treatment Form' onclick='printForm(\"#= Physician #\")'><img alt='Student Info' src='@Url.Content("~/Content/Images/printer-icon.png")' /></a>"

在此处查看:http://jsfiddle.net/OnaBai/ZwXa2/

答案 1 :(得分:0)

columns.Bound(m => m.Name).Title("Subsys #").ClientTemplate("<a href='javascript: void(0);' onclick=\"return str('ImAString');\">#= Name #</a>");

这是剃刀语法,您可以插入一些像'stringValue'

这样的任意字符串
相关问题