|
本帖最后由 her_so 于 2017-12-21 18:45 编辑
树形结构选择报错问题!
由于是代码生成的 主从表 页面中!使用 easyui-combotree树形 下拉选择! 但是页面加载时 控制台 报错!
<input id="parentId" name="parentId" type="text" style="width: 150px" class="inputxt easyui-combotree"
data-options="panelHeight:'220',
url: 'placeController.do?datagrid&field=id,placeName',
loadFilter: function(data) {
var rows = data.rows || data;
var win = frameElement.api.opener;
var listRows = win.getDataGrid().treegrid('getData');
joinTreeChildren(rows, listRows);
convertTreeData(rows, 'placeName');
return rows;
},
onSelect:function(node){
$('#parentId').val(node.id);
},
onLoadSuccess: function() {
var win = frameElement.api.opener;
var currRow = win.getDataGrid().treegrid('getSelected');
if(!'${test.id}') {
//增加时,选择当前父菜单
if(currRow) {
$('#parentId').combotree('setValue', currRow.id);
}
}else {
//编辑时,选择当前父菜单
if(currRow) {
$('#parentId').combotree('setValue', currRow.parentId);
}
}
}"/>
此处代码在其他页面运行正常
页面头部引入:
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title></title>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
树形列表数据转换js
<script type="text/javascript">
/**树形列表数据转换**/
function convertTreeData(rows, textField) {
for(var i = 0; i < rows.length; i++) {
var row = rows;
row.text = row[textField];
if(row.children) {
row.state = "open";
convertTreeData(row.children, textField);
}
}
}
/**树形列表加入子元素**/
function joinTreeChildren(arr1, arr2) {
for(var i = 0; i < arr1.length; i++) {
var row1 = arr1;
for(var j = 0; j < arr2.length; j++) {
if(row1.id == arr2[j].id) {
var children = arr2[j].children;
if(children) {
row1.children = children;
}
}
}
}
}
</script>
|
-
控制台报错
-
js相关文件引入
-
树形列表数据转换
-
easyui js加载正常
|