javascript - Nested if condition in kendo grid column template - Stack Overflow

While trying to implement condition function in kendo grid column template, there is a problem happenin

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 badges
Add a ment  | 

1 Answer 1

Reset to default 5

You 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()),

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744716338a4589640.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信