在KENDO网格中使用客户端模板连接2个列。

huangapple go评论49阅读模式
英文:

Concatenate 2 columns in KENDO grid using client template

问题

我已将我的列绑定到网格上,如下所示:

columns.Bound(p => p.LastName)
    .ClientTemplate("#=IsSpecialPerson ? '特殊信息' : ''#=LastName#");

现在,如果中间名存在,我需要将中间名与姓氏列中的姓氏之间添加一个空格。我尝试了以下方法,但没有成功:

columns.Bound(p => p.LastName)
    .ClientTemplate("#=IsSpecialPerson ? '特殊信息' : ''#=LastName# #= MiddleName != null ? MiddleName : ''#");

我在HTML上得到了无效的模板错误。

英文:

I have my column bind on the grid as follows:

columns.Bound(p => p.LastName)
     .ClientTemplate($"#=IsSpecialPerson ? 'Special Message' : ''##=LastName#")

And now I have to add middle name with a space to the last name column if exists.
I have tried the following, but no luck.

columns.Bound(p => p.LastName)
   .ClientTemplate($"#=IsSpecialPerson ? 'Special Message' : ''##=LastName# ##= MiddleName != null ? MiddleName : ''#") 

I am getting invalid template error on the html.

答案1

得分: 2

代码部分不翻译:

A quick way to check your template is to count the number of #'s. It should be an even number. If I write your template over separate lines it is easier to see where the problem is:

May I suggest this:

Put that all into one line and it should give you the result you are looking for.

英文:

A quick way to check your template is to count the number of #'s. It should be an even number. If I write your template over separate lines it is easier to see where the problem is:

#=IsSpecialPerson ? 'Special Message' : ''#
#=LastName#
##= MiddleName != null ? MiddleName : ''#  // You have 3 #'s here

May I suggest this:

#=IsSpecialPerson ? 'Special Message' : ''#
#=LastName#
#if (data.MiddleName != null) {#  // I forget if the data prefix is needed here or not
     
    #=MiddleName#
#}#

Put that all into one line and it should give you the result you are looking for.

huangapple
  • 本文由 发表于 2023年3月7日 05:35:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75656065.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定