【问题标题】:Pass variable from kendo datasource to template将变量从 kendo 数据源传递到模板
【发布时间】:2014-03-12 21:21:46
【问题描述】:

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

如果我发送数据源 Id 字段,我可以正常工作,但如果我尝试发送字符串值(医师),我会收到“意外标识符”错误。我尝试将列:字段:更改为医师,但得到相同的错误。

编辑:我可以传递任何 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>"
            },

【问题讨论】:

    标签: kendo-ui kendo-grid


    【解决方案1】:

    由于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/

    【讨论】:

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

      这是 razor 语法,您可以插入一些任意字符串,例如 'stringValue'

      【讨论】:

        猜你喜欢
        • 2016-10-10
        • 2021-01-15
        • 2019-09-12
        • 2013-12-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-06
        相关资源
        最近更新 更多