admin管理员组文章数量:1389762
While trying to implement condition function in kendo grid column template, there is a problem happening, data from my grid are not shown, my function is
function material() {
if (PCommonPortalMethods.GetSiteLanguage() == 'en') {
if (data.Unit._Key) {
Unit.UnitGlobalName
}
else ('')
}
else {
if (data.Unit._Key) {
Unit.UnitLocalName
}
else ('')
}
}
and I call it from template like : template:'#= material() #'
I tried something like that also:
template: "#if (PCommonPortalMethods.GetSiteLanguage() == 'en') {# if(data.Unit._Key) #=Unit.UnitGlobalName# else(" ") #} else { # if(data.Unit._Key) #=Unit.UnitLocalName# else(" ") #} #"
can someone help me? what am I doing wrong? Thanks
While trying to implement condition function in kendo grid column template, there is a problem happening, data from my grid are not shown, my function is
function material() {
if (PCommonPortalMethods.GetSiteLanguage() == 'en') {
if (data.Unit._Key) {
Unit.UnitGlobalName
}
else ('')
}
else {
if (data.Unit._Key) {
Unit.UnitLocalName
}
else ('')
}
}
and I call it from template like : template:'#= material() #'
I tried something like that also:
template: "#if (PCommonPortalMethods.GetSiteLanguage() == 'en') {# if(data.Unit._Key) #=Unit.UnitGlobalName# else(" ") #} else { # if(data.Unit._Key) #=Unit.UnitLocalName# else(" ") #} #"
can someone help me? what am I doing wrong? Thanks
Share Improve this question asked Jun 29, 2015 at 7:56 AviatorAviator 6134 gold badges11 silver badges27 bronze badges1 Answer
Reset to default 5You should use return
inside of it, change your script like this
function material() {
if (PCommonPortalMethods.GetSiteLanguage() === 'en') {
if (data.Unit._Key) {
return Unit.UnitGlobalName;
}
return '';
}
else {
if (data.Unit._Key) {
return Unit.UnitLocalName;
}
return '';
}
}
or we could change your script like this
function material() {
var text = '';
if(data.Unit._key) {
text = PCommonPortalMethods.GetSiteLanguage() === 'en' ?
Unit.UnitGlobalName : Unit.UnitLocalName;
}
return text;
}
Simple yet still readable, if you like to make a script template it could be like this.
<script type="text/x-kendo-template" id="template">
# if (PCommonPortalMethods.GetSiteLanguage() === 'en') { #
# if(data.Unit._Key) { #
<span> #= Unit.UnitGlobalName # </span>
# } #
#} else { #
# if(data.Unit._Key) {#
<span> #= Unit.UnitLocalName # </span>
# } #
# } #
</script>
and use it like this
template: kendo.template($("#template").html()),
本文标签: javascriptNested if condition in kendo grid column templateStack Overflow
版权声明:本文标题:javascript - Nested if condition in kendo grid column template - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744716338a2621425.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论