• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
    問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
    當前位置: 首頁 - 科技 - 知識百科 - 正文

    ASP.NET MVC異步獲取和刷新ExtJS6 TreeStore

    來源:懂視網 責編:小采 時間:2020-11-27 22:36:12
    文檔

    ASP.NET MVC異步獲取和刷新ExtJS6 TreeStore

    ASP.NET MVC異步獲取和刷新ExtJS6 TreeStore:從數據庫獲取構造樹結構是ExtJS TreePanel的核心技術,常用方法是TreeStroe里配置proxy,這種方式的root成了一個不受控制的節點。 TreeStroe的root實際是一個層疊json數據,大部分情況是直接寫一些簡單數據,但在實際應用中必定是要從數據庫讀取的。我的方法
    推薦度:
    導讀ASP.NET MVC異步獲取和刷新ExtJS6 TreeStore:從數據庫獲取構造樹結構是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")
     {
     return;
     }
     var message = Ext.String.format('Level={0}<br/>state={1}', record.data.Level, record.data.state);
     Ext.Msg.alert("節點信息", message);
    }
    

    下面是后臺C#代碼

    定義一個TreeNode類,包含TreePanel節點固有的一些屬性,也可以任意擴充,利用這個可以自定義許多附加數據,如我在里面定義Level表示節點的級別。

     [Authorize]
     [RoutePrefix("api/BasicData_API")]
     public class BasicData_APIController : ApiController
     {
     [Route("GetBasicTablesTreeSource")]
     public HttpResponseMessage GetBasicTablesTreeSource(string condition = null)
     {
     List<TreeNode> lstF = new List<TreeNode>();
     ZydAdonet z = ZydAdonet.Instance();
     string s1 = "select TableName,title from BaseDataTables order by TableName";
     string sqltext = s1;
     DataTable dt1;
     string ErrMes;
     z.Sql2DTReadOnly(s1, out dt1, null, out ErrMes);
     TreeNode tnd;
     foreach (DataRow drx in dt1.Rows)
     {
     tnd = new TreeNode
     {
     id = drx["TableName"].ToString(),
     text = drx["title"].ToString(),
     Level = 1,
     iconCls = "table_6",
     state = drx["TableName"].ToString() + " OK",
     leaf = true
     };
     lstF.Add(tnd);
     }
     TreeNode root = new TreeNode
     {
     text = "基礎數據字典",
     expanded = false,
     iconCls = "folder_close",
     Level = 0,
     state = "RootOfTree",
     leaf = true
     };
     if (lstF.Count > 0)
     {
     root.expanded = true;
     root.leaf = false;
     root.iconCls = "folder_open";
     root.children = lstF;
     }
    
     string JsonStr;
     JsonStr = JsonConvert.SerializeObject(root);
     HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, "value");
     response.Content = new StringContent(JsonStr, Encoding.GetEncoding("UTF-8"), "application/json");
     response.Headers.CacheControl = new CacheControlHeaderValue()
     {
     MaxAge = TimeSpan.FromMinutes(10)
     };
     return response;
     }
     }
    
     internal class TreeNode
     {
     public string id { get; set; }
     public string text { get; set; }
     public string iconCls { get; set; }
     public string state { get; set; }
     public bool leaf { get; set; }
     public int Level { get; set; }
     public bool expanded { get; set; }
     public List<TreeNode> children { get; set; }
     }
    
    

    在NodeClick函數中斷可以監視到更多的信息:

    最后的運行效果:

    然后更改數據表里的數據,點“刷新”就實現了TreePanel節點的刷新。

    聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    ASP.NET MVC異步獲取和刷新ExtJS6 TreeStore

    ASP.NET MVC異步獲取和刷新ExtJS6 TreeStore:從數據庫獲取構造樹結構是ExtJS TreePanel的核心技術,常用方法是TreeStroe里配置proxy,這種方式的root成了一個不受控制的節點。 TreeStroe的root實際是一個層疊json數據,大部分情況是直接寫一些簡單數據,但在實際應用中必定是要從數據庫讀取的。我的方法
    推薦度:
    標簽: ASP.NET tree extjs
    • 熱門焦點

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 1000部精品久久久久久久久| 亚洲国产精品lv| 欧美一区二区精品| 亚洲精品无码不卡在线播HE| 秋霞午夜鲁丝片午夜精品久| 日本VA欧美VA精品发布| 久久久91人妻无码精品蜜桃HD| 欧美亚洲精品在线| 99精品国产一区二区三区| 熟妇无码乱子成人精品| 亚洲国产成人a精品不卡在线| 国产精品无码专区在线观看| 久久久久国产精品| 69堂国产成人精品视频不卡| 人人妻人人澡人人爽欧美精品| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 人人妻人人澡人人爽精品日本| 欧美人与性动交α欧美精品| 国产精品视频色视频| 91精品啪在线观看国产电影| 精品国产网红福利在线观看| 2021最新国产精品网站| 精品久久久久久成人AV| 精品深夜AV无码一区二区| 日韩精品乱码AV一区二区| 中文无码精品一区二区三区| 亚洲第一区精品日韩在线播放| 青青热久久国产久精品 | 无码少妇精品一区二区免费动态| 中文字幕精品一区| 亚洲2022国产成人精品无码区| 伊人 久久 精品| 亚洲av无码国产精品夜色午夜| 野狼第一精品社区| 无码日韩精品一区二区三区免费 | 91不卡在线精品国产| 国产精品内射婷婷一级二| 国产免费久久精品丫丫| 免费精品精品国产欧美在线欧美高清免费一级在线 | 亚洲综合av永久无码精品一区二区| 亚洲欧美国产精品专区久久|