亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

 更新時間:2016年12月03日 16:16:07   作者:趙軼東  
這篇文章主要為大家詳細介紹了ASP.NET MVC異步獲取和刷新ExtJS6 TreeStore的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下

從數(shù)據(jù)庫獲取構(gòu)造樹結(jié)構(gòu)是ExtJS TreePanel的核心技術(shù),常用方法是TreeStroe里配置proxy,這種方式的root成了一個不受控制的節(jié)點。

TreeStroe的root實際是一個層疊json數(shù)據(jù),大部分情況是直接寫一些簡單數(shù)據(jù),但在實際應(yīng)用中必定是要從數(shù)據(jù)庫讀取的。我的方法是先用Ext.Ajax.request獲取root數(shù)據(jù)形成TreeStroe。定義一個全局的TreeStroe名字是mTreeStore,用Ext.Ajax.request獲得root數(shù)據(jù)。TreeStoreRefresh函數(shù)與此類似,將mTreeStore的root換為新值。TreePanel的rootVisible屬性必須為true,增加一個節(jié)點單擊事件顯示節(jié)點的信息。

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('服務(wù)器錯誤', '數(shù)據(jù)處理錯誤原因:\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('服務(wù)器錯誤', '數(shù)據(jù)處理錯誤原因:\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: '基礎(chǔ)數(shù)據(jù)字典',
 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("節(jié)點信息", message);
}

下面是后臺C#代碼

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

 [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 = "基礎(chǔ)數(shù)據(jù)字典",
    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函數(shù)中斷可以監(jiān)視到更多的信息:

最后的運行效果:

然后更改數(shù)據(jù)表里的數(shù)據(jù),點“刷新”就實現(xiàn)了TreePanel節(jié)點的刷新。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 禁用aspx頁面的客戶端緩存(防止頁面被修改)

    禁用aspx頁面的客戶端緩存(防止頁面被修改)

    默認情況下,IE打開一個網(wǎng)頁,會在本地進行緩存,在某些時候也會帶來了弊端,比如修改信息的頁面等等因為URL并沒有改變,所以IE會讀取本地緩存,這種情況特別容易出現(xiàn)在彈出對話框或窗口進行修改的方式感興趣的朋友可以了解下,或許對你有所幫助
    2013-02-02
  • asp.net XMLHttpRequest實現(xiàn)用戶注冊前的驗證

    asp.net XMLHttpRequest實現(xiàn)用戶注冊前的驗證

    用戶注冊前的驗證,提高用戶體驗。
    2009-10-10
  • asp.net下 jquery jason 高效傳輸數(shù)據(jù)

    asp.net下 jquery jason 高效傳輸數(shù)據(jù)

    jquery jason 高效傳輸數(shù)據(jù)轉(zhuǎn)自網(wǎng)上稍有修改
    2009-03-03
  • Bat自動解壓縮發(fā)布asp.net程序

    Bat自動解壓縮發(fā)布asp.net程序

    這篇文章主要介紹了Bat自動解壓縮發(fā)布asp.net程序的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-12-12
  • .NET Core自定義項目模板的全過程

    .NET Core自定義項目模板的全過程

    這篇文章主要給大家介紹了關(guān)于.NET Core自定義項目模板的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-04-04
  • ASP.NET泛型一之泛型簡介與基本語法

    ASP.NET泛型一之泛型簡介與基本語法

    這篇文章介紹了ASP.NET泛型的簡介與基本語法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-08-08
  • VsCode之使用WebView通信詳解

    VsCode之使用WebView通信詳解

    這篇文章主要介紹了VsCode之使用WebView通信詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-05-05
  • 驗證一個ASP.NET應(yīng)用程序和頁面的生命周期的實現(xiàn)代碼

    驗證一個ASP.NET應(yīng)用程序和頁面的生命周期的實現(xiàn)代碼

    我們知道ASP.NET Page的生命周期實際上是ASP.NET Application的生命周期的一部分。這個周期經(jīng)歷了HTTP Module => HTTP Handler => ASP.NET Page => Http Module這樣一個過程
    2012-04-04
  • ASP.NET?Core實時庫SignalR簡介及使用

    ASP.NET?Core實時庫SignalR簡介及使用

    這篇文章介紹了ASP.NET?Core實時庫SignalR簡介及使用方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-01-01
  • Asp.net中時間格式化的6種方法詳細總結(jié)

    Asp.net中時間格式化的6種方法詳細總結(jié)

    數(shù)據(jù)控件綁定時格式化日期方法/用DataBinder.Eval進行數(shù)據(jù)綁定時/直接用ToString方法轉(zhuǎn)換日期顯示格式/用String類轉(zhuǎn)換日期顯示格式等等,感興趣的你了解下哦,或許對你學習時間格式化有所幫助
    2013-02-02

最新評論