从数据库获取构造树结构是ExtJS TreePanel的核心技术,常用方法是TreeStroe里配置proxy,这种方式的root成了一个不受控制的节点。 TreeStroe的root实际是一个层叠json数据,大部分情况是直接写一些简单数据,但在实际应用中必定是要从数据库读取的 ...
从数据库获取构造树结构是ExtJS TreePanel的核心技术,常用方法是TreeStroe里配置proxy,这种方式的root成了一个不受控制的节点。
TreeStroe的root实际是一个层叠json数据,大部分情况是直接写一些简单数据,但在实际应用中必定是要从数据库读取的。我的方法是先用Ext.Ajax.request获取root数据形成TreeStroe。定义一个全局的TreeStroe名字是mTreeStore,用Ext.Ajax.request获得root数据。TreeStoreRefresh函数与此类似,将mTreeStore的root换为新值。TreePanel的rootVisible属性必须为true,增加一个节点单击事件显示节点的信息。
var mTreeStore = null;Ext.Ajax.request({ async: false, url: '/api/BasicData_API/GetBasicTablesTreeSource', method: 'get', success: function (response, options) { var TreeRoot = Ext.decode(response.responseText); mTreeStore = Ext.create('Ext.data.TreeStore', { root: TreeRoot }); }, failure: function (response, options) { //var responseArray = Ext.decode(response.responseText); Ext.Msg.alert('服务器错误', '数据处理错误原因:\n\r' + response.responseText); }});function TreeStoreRefresh(){ Ext.Ajax.request({ async: false, url: '/api/BasicData_API/GetBasicTablesTreeSource', method: 'get', success: function (response, options) { var TreeRoot = Ext.decode(response.responseText); if (mTreeStore != null) { mTreeStore.setRoot(TreeRoot); } }, failure: function (response, options) { //var responseArray = Ext.decode(response.responseText); Ext.Msg.alert('服务器错误', '数据处理错误原因:\n\r' + response.responseText); } });}Ext.define('TreeToolbarCls', { extend: 'Ext.toolbar.Toolbar', padding:'0 0 0 0', items: [{ text: '刷新', iconCls: 'refresh', handler: TreeStoreRefresh, height: 30, width: 65 }]});Ext.define('U1TreeCls',{ extend: 'Ext.tree.Panel', xtype: 'U1Tree_xtype', //title: '基础数据字典', rootVisible: true, width: 300, store: mTreeStore, scrollable: true, tbar:Ext.create('TreeToolbarCls'), listeners: { itemclick: NodeClick }});function NodeClick(node, record, item, index, e, eOpts){
if (typeof (record.data) == "undefined")
原标题:ASP.NET MVC 异步获取和刷新ExtJS6 TreeStore
关键词:ASP.NET
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。