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()),
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744716338a4589640.html
评论列表(0条)