Extend mini.DataGrid Usage <ul id="tree1" class="mini-tree" url="../data/tree.txt" style="width:300px;padding:5px;" showTreeIcon="true" textField="text" idField="id" > </ul>
官方api網址http://www.miniui.com/docs/api/index.html#ui=treehtml
1、建立Tree <ul id="tree1" class="mini-tree" url="../data/tree.txt" style="width:300px;padding:5px;" showTreeIcon="true" textField="text" idField="id" > </ul> 數據結構:樹形 經過url返回的數據結構以下: [ {id: "base", text: "Base", expanded: false, children: [ {id: "ajax", text: "Ajax"}, {id: "json", text: "JSON"}, {id: "date", text: "Date"}, {id: "control", text: "Control"}, {id: "messagebox", text: "MessageBox"}, {id: "window", text: "Window"} ] }, ... ]
2、建立Tree <ul id="tree1" class="mini-tree" url="../data/listTree.txt" style="width:200px;padding:5px;" showTreeIcon="true" textField="text" idField="id" parentField="pid" resultAsTree="false" > </ul> 注意:idField、parentField、resultAsTree屬性。 數據結構:列表 經過url返回的數據結構以下: [ {id: "base", text: "Base", expanded: false}, {id: "ajax", text: "Ajax", pid: "base"}, {id: "json", text: "JSON", pid: "base"}, ...... ] 其中,id和pid對應父子關係。
3、建立Tree 沒有設置url。 <ul id="tree3" class="mini-tree" style="width:300px;padding:5px;" showTreeIcon="true" textField="text" idField="id" > </ul> Javascript設置數據 var tree3 = mini.get("tree3"); tree3.loadData([ { id: "lists", text: "Lists", expanded: false, children: [ { id: "datagrid", text: "DataGrid" }, { id: "tree", text: "Tree" }, { id: "treegrid", text: "TreeGrid " } ] }, { id: "layouts", text: "Layouts", expanded: false, children: [ { id: "panel", text: "Panel" }, { id: "splitter", text: "Splitter" }, { id: "layout", text: "Layout " } ] }, { id: "navigations", text: "Navigations", expanded: false, children: [ { id: "pager", text: "Pager" }, { id: "tabs", text: "Tabs" }, { id: "navbar", text: "NavBar" }, { id: "menu", text: "Menu" } ] } ]);
4、Html標籤建立節點 <ul id="tree2" class="mini-tree" style="width:200px;padding:5px;" showTreeIcon="true"> <li> <span>MiniUI</span> <ul> <li> <span expanded="false">Form</span> <ul> <li>ComboBox</li> <li>DatePicker</li> <li>Spinner</li> <li>TreeSelect</li> </ul> </li> <li> <span expanded="false">Lists</span> <ul> <li><a href="../datagrid/datagrid.html" target="_blank" style="color:Blue;text-decoration:underline;">DataGrid</a></li> <li>Tree</li> </ul> </li> <li> <span expanded="false">Layouts</span> <ul> <li>Panel</li> <li>Splitter</li> <li>Layout</li> </ul> </li> <li> <span expanded="false">Navigations</span> <ul> <li>Tabs</li> <li>NavBar</li> <li>Menu</li> <li>Pager</li> </ul> </li> </ul> </li> </ul>
樹操做:增長、刪除、修改、移動
參考示例:增長、刪除、修改節點
增長節點
var tree = mini.get("tree1");
var node = tree.getSelectedNode();
var newNode = {};
tree.addNode(newNode, "before", node);
刪除節點
var node = tree.getSelectedNode();
tree.removeNode(node);
編輯節點
var node = tree.getSelectedNode();
tree.beginEdit(node);
移動節點
tree.moveNode(node, targetNode, "before");