ext4中怎么动态生成tree的根节点,急~~~~
我只知道静态写树的根节点,如:root: {
id: 1,
text: '根节点',
type:-1,
allowDrag: false,
expanded: true,
}
请问要动态的生成应该要怎么做啊,怎么将后台的值传过来?我是用的spring+heibernate --------------------编程问答-------------------- 自己顶一下 --------------------编程问答-------------------- 先写个根,把它隐藏,再onload事件吧再把你要的点挂上去 --------------------编程问答-------------------- //********************目录树的数据存储库
var treeStore = Ext.create('Ext.data.TreeStore',{
proxy: {
type: 'ajax',
url: 'bindTree.action'
},
reader:{
type:'json'
},
root: {
text: 'Ext JS',
id: 'src',
expanded: true
}
});
//***************************左侧目录树*********************
var tree = Ext.create('Ext.tree.Panel',{
store:treeStore,
rootVisible:false,
height:'100%',
viewConfig:{
plugins:{
ptype:'treeviewdragdrop'
}
},
dockedItems:[{
xtype:'易做图',
items:[{
text:'展开',
handler:function(){
tree.expandAll();
}
},{
text:'折叠',
handler:function(){
tree.collapseAll();
}
}]
}]
})
后台用json格式。 --------------------编程问答--------------------
--------------------编程问答--------------------
public class TreeNode {
private String id;
private String href;
private String text;
private TreeNode parent;
private List<TreeNode> children = new ArrayList<TreeNode>();
public TreeNode() {
}
public TreeNode(String id, String text) {
this.id = id;
this.text = text;
}
public TreeNode(String id, String text, String href) {
this.id = id;
this.text = text;
this.href = href;
}
/**
* @return the href
*/
public String getHref() {
return href;
}
/**
* @param href
* the href to set
*/
public void setHref(String href) {
this.href = href;
}
/**
* @return the id
*/
public String getId() {
return id;
}
/**
* @param id
* the id to set
*/
public void setId(String id) {
this.id = id;
}
/**
* @return the parent
*/
public TreeNode getParent() {
return parent;
}
/**
* @param parent
* the parent to set
*/
public void setParent(TreeNode parent) {
this.parent = parent;
}
/**
* @return the text
*/
public String getText() {
return text;
}
/**
* @param text
* the text to set
*/
public void setText(String text) {
this.text = text;
}
public void addChild(TreeNode node) {
children.add(node);
}
public boolean isLeaf() {
return children.size() == 0;
}
public Iterator<TreeNode> iterator() {
return children.iterator();
}
public static String getTree(TreeNode node) {
StringBuffer tree = new StringBuffer();
int index = 0;
if(node.isLeaf()) {
tree.append("{");
tree.append("id: '" + node.getId());
tree.append("', text: '"
+ (node.getText() == null ? "" : node.getText()));
tree.append("', href: '"
+ (node.getHref() == null ? "" : node.getHref()));
tree.append("', leaf: " + node.isLeaf());
tree.append("}");
}
else {
Iterator<TreeNode> it = node.iterator();
tree.append("{");
tree.append("id: '" + node.getId());
tree.append("', text: '" + node.getText());
tree.append("', leaf: " + node.isLeaf());
tree.append(", children: [");
while(it.hasNext()) {
if(index > 0) {
tree.append(", ");
}
TreeNode child = it.next();
tree.append(getTree(child));
index++;
}
tree.append("]");
tree.append("}");
}
return tree.toString();
}
--------------------编程问答-------------------- 高人,谢谢啊
var root = new Ext.tree.TreeNode({
id: "root",
text: "root"
});
//rsObj json string
createTree(root, rsObj);
/**
* The method is used to create tree in page.
*
* @param parentNode parent node.
* @param nodes child nodes.
*/
function createTree(parentNode, nodes) {
for(var i = 0; nodes.length && i < nodes.length; i++) {
var child = new Ext.tree.TreeNode({
id: nodes[i].id,
text: nodes[i].text,
leaf: nodes[i].leaf,
href: nodes[i].href,
singleClickExpand: true,
listeners: {
"click" : function() {
if(this.leaf) {
}
}
}
});
if("root" == nodes[i].id) {
child = parentNode;
}
else {
parentNode.appendChild(child);
}
if(!nodes[i].leaf) {
createTree(child, nodes[i].children);
}
}
}
补充:Java , Web 开发