Javascript 剑道ui网格模板,如果有
以下代码不起作用。如果这里有条件,谁能帮我写和Javascript 剑道ui网格模板,如果有,javascript,jquery,kendo-ui,kendo-grid,Javascript,Jquery,Kendo Ui,Kendo Grid,以下代码不起作用。如果这里有条件,谁能帮我写和其他人 function getMyColumns() { return [{ field: "xxx", title: "1st", width: "75px", }, { field: "ChoiceCode", title: "2nd", width: "75px", template: "#if(ChoiceCode =
其他人
function getMyColumns() {
return [{
field: "xxx",
title: "1st",
width: "75px",
}, {
field: "ChoiceCode",
title: "2nd",
width: "75px",
template: "#if(ChoiceCode == null) {# #} else If(mychoice == ChoiceCode) {#" +
"{ #<div style='background-color:lightgreen'><span>#=ChoiceCode#</span></div>#}" +
"else {# <span>#=secondChoiceCode#</span> #}" +
"#}#"
}, {
}];
}
函数getMyColumns(){
返回[{
字段:“xxx”,
标题:“第一”,
宽度:“75px”,
}, {
字段:“ChoiceCode”,
标题:“第二”,
宽度:“75px”,
模板:“#if(ChoiceCode==null){##}else if(mychoice==ChoiceCode){#”+
“{##=选择代码##}”+
“else{###=第二选择代码##}”+
"#}#"
}, {
}];
}
在选项字段中,如果它为空,我想显示一个空字符串,如果它有一个值,并且它与我的选择匹配,我想用绿色突出显示该单元格,如果它与我的选择不匹配,请不要突出显示它 可能的打字错误
}else If(mychoice==ChoiceCode){
应该是
}否则,如果(mychoice==ChoiceCode){我个人会修改它,这样更容易阅读和修改 与其将所有逻辑放在这里,不如将其拉入函数,使模板命令看起来像:
template: "#=highlighter(data.ChoiceCode, data.mychoice, data.secondChoiceCode) #"
函数的脚本如下所示:
function(choiceCode, myChoice, secondChoiceCode) {
var retString = '';
if (choiceCode === null || choiceCode === undefined) {
retString = '';
} else if (myChoice === choiceCode) {
resString = '<div style="background-color:lightgreen;"><span>' +
choiceCode + '</span></div>'
} else {
retString = '<span>' + secondChoiceCode + '</span>';
}
return retString;
}
函数(choiceCode、myChoice、secondChoiceCode){
var retString='';
if(choiceCode==null | | choiceCode==undefined){
retString='';
}else if(myChoice==choiceCode){
resString=''+
选择代码+“”
}否则{
retString=''+secondChoiceCode+'';
}
返回字符串;
}
然后,您就不必记住各种大括号应该放在哪里,并在模板中转义它们
显然,将函数更改为返回数据所需的方式,但这是基于我在提供的原始代码中看到的内容。我假设变量是每行绑定模型中的属性
编辑
我添加了以下演示,希望能有所帮助:
如果将模板内联,则将是:
#if(ChoiceCode == null) {# #} else If(mychoice == ChoiceCode) {# { #<div style='background-color:lightgreen'><span>#=ChoiceCode#</span></div>#}else {# <span>#=secondChoiceCode#</span> #} #}#
注意到什么不对劲了吗?我想应该是这样的:
if(ChoiceCode == null) { }
else If(mychoice == ChoiceCode) {
<div style='background-color:lightgreen'><span>#=ChoiceCode#</span></div>
}
else {
<span>#=secondChoiceCode#</span>
}
if(ChoiceCode==null){
else If(mychoice==ChoiceCode){
#=选择码#
}
否则{
#=第二选择码#
}
内联版本:
# if(ChoiceCode == null) { # # } else if (mychoice == ChoiceCode) { #<div style='background-color:lightgreen'><span>#=ChoiceCode#</span></div> # } else { # <span>#=secondChoiceCode#</span> # } #
template: "#if(ChoiceCode == null) {# #} else if(mychoice == ChoiceCode) {#" +
"<div style='background-color:lightgreen'><span>#=ChoiceCode#</span></div>#}" +
"else {# <span>#=secondChoiceCode#</span> #}#";
#if(ChoiceCode==null){##}else if(mychoice==ChoiceCode){###}else{###else{#second ChoiceCode##
代码版本:
# if(ChoiceCode == null) { # # } else if (mychoice == ChoiceCode) { #<div style='background-color:lightgreen'><span>#=ChoiceCode#</span></div> # } else { # <span>#=secondChoiceCode#</span> # } #
template: "#if(ChoiceCode == null) {# #} else if(mychoice == ChoiceCode) {#" +
"<div style='background-color:lightgreen'><span>#=ChoiceCode#</span></div>#}" +
"else {# <span>#=secondChoiceCode#</span> #}#";
template:“#if(ChoiceCode==null){##}else if(mychoice==ChoiceCode){#”+
“#=选择代码##}”+
“else{###=第二选择代码##}”;
模板中有一些外括号({)
试试这个
function getMyColumns() {
return [{
{
field: "xxx",
title: "1st",
width: "75px",
}, {
field: "ChoiceCode",
title: "2nd",
width: "75px",
template: "#if(ChoiceCode == null) {# #} else if(mychoice == ChoiceCode) {#" +
"<div style='background-color:lightgreen'><span>#=ChoiceCode#</span></div>#}" +
"else {# <span>#=secondChoiceCode#</span> #}#",
}, {
}];
}
函数getMyColumns(){
返回[{
{
字段:“xxx”,
标题:“第一”,
宽度:“75px”,
}, {
字段:“ChoiceCode”,
标题:“第二”,
宽度:“75px”,
模板:“#if(ChoiceCode==null){##}else if(mychoice==ChoiceCode){#”+
“#=选择代码##}”+
“else{###=第二选择代码##}”,
}, {
}];
}
我尝试创建函数并将登录名放在那里,但也会出现错误“未捕获的引用错误xxx未定义”。感谢您的回复。正如我在之前的评论中提到的,我已经尝试过它会给出错误“未捕获引用错误:荧光灯未定义我正在使用angularJSok我在我的代码中发现了一个错误,我已经修复了。下面是一个演示,向您展示Angular(我不得不说这不是我的强项)这帮了我的忙-角度积分在剑道中是无用的,所以这对我来说很有用!非常感谢你,非常好的解释..我总是不知道如何放置#@bansi以及在哪里放置#@bansi当你感到困惑时,把它当作纯代码来编写,然后添加哈希,然后添加到代码中,就像我上面所做的那样,它变得更容易理解。