2016-03-23 65 views
0

我有一个剑道mvc网格,并使用客户端模板作为列,我写了一个JavaScript函数在模板中返回脚本块,但它似乎不工作,没有JavaScript错误。我也尝试将脚本直接写入客户端模板,但它不工作。剑道mvc网格ClientTemplate javascript功能不工作

// HTML在客户端模板

.Columns(columns => 
    { 

    columns.Template(e => 
    { }).ClientTemplate(

     "<div class='table-responsive'>" + 
       "<table border='0' class='table' >" + 

       ...................................     

       "</table>" + 
     "</div>"+ 
      "#=AlignDiv(Id)#" 
         ); 
     }) 

// javascript函数返回一个脚本块作为字符串

 <script type="text/javascript"> 
     function AlignDiv(Id) { 
     var result = "<script> $('.calDiv"+Id+"').map(function() {" + 
      "return $(this).Height();" + 
     "}).get()," + 
     "maxHeight = Math.max.apply(null, heights);" + 
     "$('.calDiv" + Id + "').height(maxHeight);" + 
     "alert('test')<\/script>"; 
     return result; 
    } 

非常感谢, 丹尼斯

回答

0

为了格式有条件选择动作的Kendo Grid列值可以使用下面的一个合适示例。欲了解更多信息:How Do I Have Conditional Logic in a Column Client Template?


UI为Javascript:

{ 
    field: "EmployeeName", type: "string", width: "55px", title: "Employee Name", 
      template: "#= GetEditTemplate(data) #" 
} 


UI的MVC:

... 
columns.Bound(t => t.EmployeeName) 
.Title("Status Name") 
.Template(@<text></text>) 
.ClientTemplate("#= GetEditTemplate(data)#").Width("55px"); 
... 


JavaScript方法:

<script> 
//Change the color of the cell value according to the given condition 
function GetEditTemplate(data) { 
    var html; 

    if (data.StatusID == 1) { 
     html = kendo.format(
     //"<a class=\"k-button\" href='" + '@Url.Action("Edit1", "Controller")' + "/{0}" + " '>Edit</a> ", 
     "<span class='text-success'>" + 
     data.EmployeeName 
     + "</span>" 
     ); 
    } 
    else { 
     html = kendo.format(
     //"<a class=\"k-button\" href='" + '@Url.Action("Edit2", "Controller")' + "/{0}" + " '>Edit</a> ", 
     "<span class='text-danger'>Cancel</span>" 
     ); 
    } 
    return html; 
} 
</script> 

希望这有助于...