2013-03-14 263 views
0

我注意到,有可能在列部分的模板内的一些剑道逻辑和变量。剑道变量在网格

这是我的专栏部分模板

template: "#= myVariable# #if(myBoolean) {# <img src='/images/myImage.png' /> #}#" 

请做笔记的例子MYVARIABLE和myBoolean是网格的每行的变量(字段)。 不幸的是我尝试下在模板中的命令部分是相同的。我得到以下错误“的ReferenceError:MYVARIABLE没有定义”

有没有办法在命令部分添加变量,因为它与列发生什么呢?

回答

0

据我所知在columns.command使用模板甚至没有记录在案:虽然它的工作原理。你可以做这样的事情:

columns : [ 
    { 
     command: { 
      template : "# console.log('this', this); console.log('data', data); # toto" 
     } 
    }, 
    ... 
] 

甚至像:

command: { 
    template : function (arg) { 
     console.log("this" ,this); 
     console.log("arg", arg); 
     console.log("data", data); 
     return "toto"; 
    } 
} 

但是模板的回报需要一个string并在浏览器的控制台,您将看到thiswindowarg是对象commanddataarray包含网格数据。

虽然可以包括额外的参数为:

command: { 
    template : function (arg) { 
     console.log("this" ,this); 
     console.log("arg", arg); 
     console.log("arg.a", arg.a); 
     console.log("data", data); 
     return "toto"; 
    }, 
    a: "extra argument" 
} 

如果我再补充一点可以通过arg.a来访问你,因为该元素仍未插入仍不能得到当前行data获得一个额外的a说法。

取而代之的是什么,我的建议是做这样的事情:

columns : [ 
    { 
     title: " ", 
     template: "#= myVariable# #if(myBoolean) {# <img src='/images/myImage.png' /> #}#" 
    }, 
    ... 
] 

你并不需要把它作为命令,对不对?你为什么需要它作为命令?