我想更新primefaces树的子节点而不从服务器中拉出整个树。
我可以更新整个树,但不能仅特定节点的子项...
编辑:
这是我的代码示例:
<p:tree value="#{cc.tree}" var="wrapper" id="tree" widgetVar="tree" styleClass="commentTree-#{cc.id}">
<p:treeNode id="treeNode" styleClass="treenode-#{wrapper.id}">
Hallo: #{wrapper.text}
</p:treeNode>
</p:tree>
现在我想更新特定的treenode。
function findIDbySelector(selector) {
return $(selector).first().attr('id');
}
function updateComponent(clientID) {
var ajax_json = {};
ajax_json['source'] = '#{cc.id}';
ajax_json['update'] = clientID;
PrimeFaces.ajax.AjaxRequest(ajax_json);
}
[...]
updateComponent(findIDbySelector('.treenode-1'));
正如我所说,我可以更新整个树,但我只想更新一个Treenode。
(代码可能包含错误/拼写错误,因为它被删除)
答案 0 :(得分:1)
我在primefaces源代码中爬了一下,看到他们支持加载孩子这对我来说足够了(我可以将节点的内容包装到一个面板中并更新它和孩子们。)
为了更新孩子,我修改了primefaces expandnode方法:
function loadNodes(tree, c) {
var a = tree;
if (tree.cfg.dynamic) {
if (tree.cfg.cache && c.children(".ui-treenode-children").children().length > 0) {
tree.showNodeChildren(c);
return
}
if (c.data("processing")) {
PrimeFaces.debug("Node is already being expanded, ignoring expand event.");
return
}
c.data("processing", true);
var b = {
source: tree.id,
process: tree.id,
update: tree.id,
formId: tree.cfg.formId
};
b.onsuccess = function (j) {
var g = $(j.documentElement),
h = g.find("update");
for (var e = 0; e < h.length; e++) {
var l = h.eq(e),
k = l.attr("id"),
f = l.text();
if (k == a.id) {
c.children(".ui-treenode-children").html(f);
a.showNodeChildren(c)
} else {
PrimeFaces.ajax.AjaxUtils.updateElement.call(tree, k, f)
}
}
PrimeFaces.ajax.AjaxUtils.handleResponse.call(tree, g);
return true
};
b.oncomplete = function () {
c.removeData("processing")
};
b.params = [{
name: tree.id + "_expandNode",
value: a.getRowKey(c)
}];
if (tree.hasBehavior("expand")) {
var d = tree.cfg.behaviors.expand;
d.call(tree, c, b)
} else {
PrimeFaces.ajax.AjaxRequest(b)
}
} else {
tree.showNodeChildren(c);
tree.fireExpandEvent(c)
}
}
示例调用可以是:
loadNodes(tree, $('#j_idt62\\:tree\\:0'));
其中tree
是p:tree的WidgetVar