基于jQuery easyUI 怎么获取树节点的id并且删除他
展开全部
为jQuery-easyui 树添加,删除,修改树的节点,可能有人会说操作完成以后刷新一下不就可以了吗。这种做法是可以,但是如果你的数据有很多,超过几万条。操作完成后在刷新会很慢,效率不高。我们这里要讨论如何在不刷新的情况下外树添加,修改,删除节点。
首先在主页面添加几个方法:
[javascript] view plain copy
function removeRole(){
var node = $("#tt22").tree("getSelected");
$('#tt22').tree('remove', node.target);
}
function appendRole(leafText) {
var root = $("#tt22").tree('getRoot');
$("#tt22").tree("append",{
parent: root.target,
data: [{
"text":leafText
}]
});
}
function updateRole(nodeText) {
var node = $("#tt22").tree("getSelected");
if(node) {
node.text = nodeText;
$("#tt22").tree("update", node);
}
}
然后在操作的时候,比如我添加一个角色,在action中添加三个变量: name:角色名称 operate:对应的操作 role_id:角色Id
[java] view plain copy
request.setAttribute("roleName", roleName);
request.setAttribute("operate", operate);
request.setAttribute("role_id", role_id);
然后在角色页面调用主页面定义的三个方法即可:
[javascript] view plain copy
$(function() {
var upd_flg = "${upd_flg}";
var add_role_id = "${add_role_id}";
var add_role_name = "${add_role_name}";
if((upd_flg == null) || (upd_flg == "")) {
return;
}
var leafText = "<a href=\"<%=path%>/admin/roleListOnload.do?role_id=";
leafText = leafText + add_role_id;
leafText = leafText + "\"";
leafText = leafText + " target=\"content_frame\">";
leafText = leafText + add_role_name;
leafText = leafText + "</a>";
if(upd_flg == "1") {
//新增
self.parent.appendRole(leafText);
return;
}
if(upd_flg == "2") {
//修改
self.parent.updateRole(leafText);
return;
}
if(upd_flg=="3"){
//删除
self.parent.removeRole();
return;
}
});
首先在主页面添加几个方法:
[javascript] view plain copy
function removeRole(){
var node = $("#tt22").tree("getSelected");
$('#tt22').tree('remove', node.target);
}
function appendRole(leafText) {
var root = $("#tt22").tree('getRoot');
$("#tt22").tree("append",{
parent: root.target,
data: [{
"text":leafText
}]
});
}
function updateRole(nodeText) {
var node = $("#tt22").tree("getSelected");
if(node) {
node.text = nodeText;
$("#tt22").tree("update", node);
}
}
然后在操作的时候,比如我添加一个角色,在action中添加三个变量: name:角色名称 operate:对应的操作 role_id:角色Id
[java] view plain copy
request.setAttribute("roleName", roleName);
request.setAttribute("operate", operate);
request.setAttribute("role_id", role_id);
然后在角色页面调用主页面定义的三个方法即可:
[javascript] view plain copy
$(function() {
var upd_flg = "${upd_flg}";
var add_role_id = "${add_role_id}";
var add_role_name = "${add_role_name}";
if((upd_flg == null) || (upd_flg == "")) {
return;
}
var leafText = "<a href=\"<%=path%>/admin/roleListOnload.do?role_id=";
leafText = leafText + add_role_id;
leafText = leafText + "\"";
leafText = leafText + " target=\"content_frame\">";
leafText = leafText + add_role_name;
leafText = leafText + "</a>";
if(upd_flg == "1") {
//新增
self.parent.appendRole(leafText);
return;
}
if(upd_flg == "2") {
//修改
self.parent.updateRole(leafText);
return;
}
if(upd_flg=="3"){
//删除
self.parent.removeRole();
return;
}
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询