Skip to content

Commit

Permalink
修复jstree在编辑情况下找不到选中的子节点
Browse files Browse the repository at this point in the history
  • Loading branch information
jianyan74 committed Dec 28, 2018
1 parent e51d462 commit 6965e23
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
5 changes: 0 additions & 5 deletions backend/modules/sys/controllers/AuthRoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ public function actionEdit()
// 插件权限管理
list($plugTreeData, $plugTreeCheckIds) = $sysAuth->getAddonsAuthJsTreeData($name);

// $userTreeData = ArrayHelper::itemsMerge($userTreeData, 'id', 0, 'parent');


// p($userTreeData);die();

// jq冲突禁用
$this->forbiddenJq();

Expand Down
48 changes: 33 additions & 15 deletions backend/modules/sys/views/auth-role/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@
showCheckboxTree(plugTreeData, plugTreeId, plugTreeCheckIds);

/**
* 带checkbox的树形控件使用说明
* @data 应该是一个js数组
* @id: 将树渲染到页面的某个div上,此div的id
* @checkId:需要默认勾选的数节点id;1.checkId="all",表示勾选所有节点 2.checkId=[1,2]表示勾选id为1,2的节点
* 节点的id号由url传入json串中的id决定
*/
* 带checkbox的树形控件使用说明
* @data 应该是一个js数组
* @id: 将树渲染到页面的某个div上,此div的id
* @checkId:需要默认勾选的数节点id;1.checkId="all",表示勾选所有节点 2.checkId=[1,2]表示勾选id为1,2的节点
* 节点的id号由url传入json串中的id决定
*/
function showCheckboxTree(data, id, checkId){

for (var i = 0; i < data.length; i++){
Expand Down Expand Up @@ -140,20 +140,38 @@ function getCheckTreeIds(treeId) {
$("#"+treeId).jstree('open_all');

var ids = [];
$("#"+treeId).find("li").each(function(){
var liId = $(this).attr("id");
if ($("#" + liId + " > a").hasClass("jstree-clicked") || $("#" + liId + " > a > i").hasClass("jstree-undetermined")) {
// 还原匹配后的字符串id
liId = liId.replace(/---/g, '/');
liId = liId.replace(/--/g, ':');

ids.push(liId);
var treeNode = $("#"+treeId).jstree(true).get_selected(true);

for (var i = 0; i < treeNode.length; i++) {

var node = treeNode[i];
var nodeId = checkMatch(node.original.id);

// 判断是否重复
if($.inArray(nodeId, ids) == -1) {
ids.push(nodeId);
}
});

for (var j = 0; j < node.parents.length; j++) {
// 判断是否重复
var parentId = checkMatch(node.parents[j]);
if (parentId != "#" && $.inArray(parentId, ids) == -1) {
ids.push(parentId);
}
}
}

return ids;
}

// 转换字符串
function checkMatch(checkId) {
checkId = checkId.replace(/---/g, '/');
checkId = checkId.replace(/--/g, ':');

return checkId;
}

// 提交表单
function submitForm(){

Expand Down

0 comments on commit 6965e23

Please sign in to comment.