英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论