KendoUI Grid - 如何以声明方式将MVVM数据列模板设置为外部模板?

时间:2013-06-03 08:20:15

标签: kendo-ui

我正在努力将声明设置网格列设置为外部模板

这是我的模板

<script type="text/x-kendo-template" id="someTemplate">
    <div>
        <label> ${firstName}</label>  
        <label>${lastName}</label>
    </div>
</script>

这里是网格声明

<div data-role="grid" data-bind="source: people" data-columns='[
    {"field": "firstName",
     "title": "Full Name",
     "template": "kendo.template($("#someTemplate"))"
    }
]'></div>

这里的JS Fiddle再现了我的问题: JSFiddle repro

2 个答案:

答案 0 :(得分:7)

您的代码中有2个错误:

  1. 你必须从脚本元素的html中创建模板
  2. 你必须直接调用kendo.template(...),因为它是一个函数,而不是引号之间。
  3. 这给出了这样的代码:

    "template": kendo.template($("#someTemplate").html())
    

    请参阅此jsfiddle:http://jsfiddle.net/bSGdW/9/

答案 1 :(得分:2)

经过几个小时的过期,我发现了......

模板:kendo.template($(&#34; \\#check-results-template&#34;)。html())

所以请注意&#39;#&#39;哪里使用剑道的东西!!