不了解在网格中生成复选框的此kendo模板 [英] Not understanding this kendo template that generates a checkbox in a grid

查看:77
本文介绍了不了解在网格中生成复选框的此kendo模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不了解Kendo模板的基本知识,所以也许有人可以向我解释一下。网格中单元格的模板示例来自Telerik示例代码。

I'm not understanding something basic about Kendo templates, so maybe someone can explain this to me. This example of a template for a cell in a grid comes from Telerik sample code.

template:"<input type='checkbox' #= IsAdmin ? checked='checked':'' # />

最终,这会生成一个输入标记,如果IsAdmin的值为true,则包含 checked ='checked'

Ultimately, this produces an input tag which, if the value of IsAdmin is true, will include "checked='checked'"

我不明白评估环境

#= IsAdmin ? checked = 'checked' : '' #

文档说 #=表示渲染为文字(无论这意味着什么),我理解IsAdmin是评估/执行模板时提供的值。

Documentation says that "#=" indicates "render as literal" (whatever that means), and I understand that "IsAdmin" is a value provided when the template is evaluated/executed.

什么跟随#=看起来像Javascript,但如果只是那样,它只会将名为checked的变量的值设置为'checked'或空字符串。

What follows the #= looks like Javascript, but if it were only that, it would merely set the value of a variable named "checked" to either 'checked' or an empty string.

这里的?运算符真的是javascript,还是Kendo模板语言?我没有看到过与运营商特定的Kendo特定语言。但如果这是真的一个Javascript?运算符,它是如何工作的,我们从这里得到一个文字checked ='checked'而不是设置一个名为checked的var,值为'checked'。

Is the ? operator here really javascript, or is it Kendo templating language? I've seen no mention of a Kendo-specific language with operators. But if this is truly a Javascript ? operator, how does it work that we get a literal "checked='checked' out of this instead of setting a var named "checked" with value 'checked'.

困惑地打电话给我。

推荐答案

这是JavaScript。使用此模板字符串:

It's JavaScript. Using this template string:

"<input type='checkbox' #= isAdmin ? checked='checked' : '' # />"

Template.compile将生成如下函数:

Template.compile will generate a function like this one:

function anonymous(data) {
    var o, e = kendo.htmlEncode;
    with(data) {
        o = '<input type=\'checkbox\' ' + (isAdmin ? checked = 'checked' : '') + ' />';
    }
    return o;
}

如您所见,您的模板部分无需更改即可使用。
渲染单元格时,将执行此函数(传入您的数据项,例如网格的行模型),并将结果字符串用作单元格的内容。

As you can see, your template section is used without changes. When your cell is rendered, this function is executed (your data item, e.g. the grid's row model, is passed in) and the resulting string is used as content for the cell.

从呈现的HTML的角度来看,这里:

From the perspective of the rendered HTML, this here:

"<input type='checkbox' #= isAdmin ? checked='checked' : '' # />"

相当于:

"<input type='checkbox' #= isAdmin ? 'checked' : '' # />"

因为 checked ='checked'将简单评估为'已检查'。
然而,使用第一个变体也会在传递给模板函数的数据上设置 checked 属性(参见演示图示

since checked='checked' will simply evaluate to 'checked'. Using the first variant however will also set the checked attribute on the data which is passed into the template function (see demo for illustration).

这篇关于不了解在网格中生成复选框的此kendo模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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