我通過 API 獲取 JSON 數據并使用 Kendo UI 將其顯示在表格中。$scope.ReportViewGrid = function ReportViewGrid(jsonData) { if (jsonData == null) return; var fileName = "ReportView"; var grid = $("#ReportViewGrid").kendoGrid({ toolbar: [{ template: "<input type='button' class='k-button' value='Back' onclick='back()' />" }], editable: false, filterable: true, resizable: true, pageable: { pageSize: 10, buttonCount: 5 }, columns: jsonData.columns, dataSource: { data: jsonData.children }, }).data("kendoGrid");}<div id="ReportViewGrid"></div>上面的代碼完美地顯示了數據。網格中有多個列,如下所示:-----------------C1 | C2 | C3 | C4-----------------v1 | v2 | v3 | v4x1 | x2 | x3 |y1 | y2 | y3 |z1 | z2 | z3 | z4Column1 使用模板進行鏈接。但我想獲取鏈接數據,其中我在 column4 中具有價值,否則為普通文本。我已經嘗試了以下代碼并嘗試翻轉條件,但鏈接總是出現。... if("uName".equalsIgnoreCase(uNameField)){ template = "# if (\"#=encodeURI(md5hash)#\".equals(\"\") ) { #" +" <span>#=fileName#</span>" +" # } else{ #" +" <a style=\"cursor: pointer;\" onclick='expand(\"fileDetailForDuplicateFile\",\"#=encodeURI(fileName)#\",\"#=encodeURI(md5hash)#\")'>#=fileName#</a>" +" #} #"; nodeColumns.setTemplate(template); } root.addColumns(nodeColumns); } root.addLinkedColumn("uName"); Gson gson = new Gson(); return gson.toJson(root);有什么我想念的嗎?任何幫助都會很棒。
1 回答

小唯快跑啊
TA貢獻1863條經驗 獲得超2個贊
我發現這對于使用 data.xx 在模板內部進行檢查很有用,如下所示:-
template = "# if(data.md5hash == ''){ #" +
" <span>#=fileName#</span> " +
" #} else {#" +
" <a style=\"cursor: pointer;\" onclick='expand(\"fileDetailForDuplicateFile\",\"#=encodeURI(fileName)#\",\"#=encodeURI(md5hash)#\")'>#=fileName#</a>" +
" # } #";
添加回答
舉報
0/150
提交
取消