剑道外部模板中是否可能有此代码等效代码 [英] Is it possible have this code equivalent code in kendo external template

查看:117
本文介绍了剑道外部模板中是否可能有此代码等效代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此dojo 及其内联模板

  var actionName = 'read';
    $("#grid").kendoGrid({
      columns: [
        { field: "name" },
        { field: "age" }
      ],
      dataSource: [
        { name: "Jane Doe", age: 30, read: true, actionName: actionName }
      ],
      detailTemplate: "<div> #:" + actionName  +"# </div>"
    });

此dojo 及其外部模板:

<script id="detailTemplate" type="text/x-kendo-template">
        #: actionName #
</script> 


var actionName = 'read';
$("#grid").kendoGrid({
  columns: [
    { field: "name" },
    { field: "age" }
  ],
  dataSource: [
{ name: "Jane Doe", age: 30, read: true, actionName: actionName }
  ],
  detailTemplate: function(dataItem){ 
    return kendo.template($("#detailTemplate").html())(dataItem);
  }
});

在第一个detailTemplate: "<div> #:" + actionName +"# </div>"中,我可以渲染值:true,但是在第二个中,#: actionName #中,我可以渲染read.

In first one detailTemplate: "<div> #:" + actionName +"# </div>" I can render value: true however in second one wiht #: actionName # I can render read.

所以我的问题是如何呈现为值true

So my question how can I render to value true

推荐答案

(您命名的)参数 dataItem 接管当前行中的数据.然后,您需要编写要渲染的属性. dataItem 对整个模板均有效.

The parametr (which you named) dataItem takes over data from current row. Then you need to write property which you want to render. dataItem is valid for whole template.

<script id="detailTemplate" type="text/x-kendo-template">
    #: read #
</script>

detailTemplate: function(dataItem){ 
    return kendo.template($("#detailTemplate").html())(dataItem);
}

应该足够了.

Dojo示例

detailTemplate中函数的参数将包含行中对象的所有属性(即使在列中也不可见).因此,如果您要进行一些特殊的计算或执行某些操作,则可以在detailtemplate函数中进行操作,并创建可以按名称在模板中使用的新属性.

Parameter of function in detailTemplate will contains all properties from object in row (even not visible as column). So if you will do some special calculations or something you can do it in detailtemplate function and create new property which will be accesible by name in template.

Dojo示例2

如果要运行(假设)某个命令,该命令以字符串形式存在,则必须使用 eval eval 功能.此函数将执行文本.这意味着如果您将某些功能名称用作eval参数,则将执行此功能.

If you want run (let's say) some command, which is in string you have to use eval function. This function will execute the text. It means if you will use some functuion name as eval parameter, this function will be executed.

Dojo示例3

但是,我敢从这个站点引用一个重要的段落:

Yet, I dare to quote one important paragrapg from this site: eval - mozila developer

不要不必要地使用eval!

eval()是一个危险的函数,该函数以调用者的特权执行它传递的代码.如果 您使用可能受到恶意软件影响的字符串运行eval() 一方,您可能最终在用户的计算机上运行恶意代码 拥有您的网页/扩展程序的权限.更重要的是, 第三方代码可以看到调用eval()的范围, 可能以类似功能的方式导致可能的攻击 不敏感.

eval() is a dangerous function, which executes the code it's passed with the privileges of the caller. If you run eval() with a string that could be affected by a malicious party, you may end up running malicious code on the user's machine with the permissions of your webpage / extension. More importantly, third party code can see the scope in which eval() was invoked, which can lead to possible attacks in ways to which the similar Function is not susceptible.

eval()通常也比其他方法慢,因为它必须 调用JS解释器,同时优化许多其他结构 由现代JS引擎提供.

eval() is also generally slower than the alternatives, since it has to invoke the JS interpreter, while many other constructs are optimized by modern JS engines.

对于eval()来说,有更安全(更快)的替代品. 用例.

There are safer (and faster!) alternatives to eval() for common use-cases.

这篇关于剑道外部模板中是否可能有此代码等效代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆