`
eimhee
  • 浏览: 2151255 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Tree non-async creation "bug" - Ext JS

阅读更多
When building a tree without using a treeloader, I can't seem to be able to specify the children of a node. Instead, I have to manually call "new Ext.tree.TreeNode()" for every node I want and then manually add it to the tree using the appendChild() method. Ideally, we should be able to pass a config as deep as necessary (like we can with AsyncTreeNode) and it'll all get added to the tree.

Does not work (grandchildren aren't created):

      Ext.onReady(function() { 
       
         var tree = new Ext.tree.TreePanel('tree'); 

         var root = new Ext.tree.TreeNode({ 
            text : 'My Root', 
            id : 'my-root'
         }); 
         
         tree.setRootNode(root);

         var child1 = new Ext.tree.TreeNode({ text: 'Child 1', id: 'child-1' });
         var child2 = new Ext.tree.TreeNode({ text: 'Child 2', id: 'child-2' });
         var child3 = new Ext.tree.TreeNode({ text: 'Child 3', id: 'child-3', children: [ 
                  { text: 'Grandchild 1', id: 'grandchild-1' }, 
                  { text: 'Grandchild 2', id: 'grandchild-2' } 
               ]});
          root.appendChild(child1, child2, child3);
          
         tree.render(); 
      });
Also does not work (children aren't even created):

      Ext.onReady(function() { 
       
         var tree = new Ext.tree.TreePanel('tree'); 

         var root = new Ext.tree.TreeNode({ 
            text : 'My Root', 
            id : 'my-root', 
            children: [ 
               { text: 'Child 1', id: 'child-1' }, 
               { text: 'Child 2', id: 'child-2' }, 
               { text: 'Child 3', id: 'child-3', children: [ 
                  { text: 'Grandchild 1', id: 'grandchild-1' }, 
                  { text: 'Grandchild 2', id: 'grandchild-2' } 
               ]} 
            ] 
         }); 
          
         tree.setRootNode(root);      // Generates error: tree has no properties! 
          
         tree.render(); 
      });
Reply With Quote
  #2  
Old 03-04-2007, 09:21 PM
Default

In order to get the automated conversion of JSON to nodes, it goes through the TreeLoader. Think of the TreeLoader as not only loading through the server, but also in the browser as well. So you need to use an AsyncTreeNode instead of TreeNode. Luckily this involves no extra work.
Reply With Quote
  #3  
Old 03-04-2007, 10:06 PM
Default

Ok, fair enough. So, theoretically, changing Ext.tree.TreeNode to Ext.tree.AsyncTreeNode should do the trick. However, the following doesn't work:

      Ext.onReady(function() { 
       
         var tree = new Ext.tree.TreePanel('tree'); 

         var root = new Ext.tree.AsyncTreeNode({ 
            text : 'My Root', 
            id : 'my-root', 
            children: [ 
               { text: 'Child 1', id: 'child-1' }, 
               { text: 'Child 2', id: 'child-2' }, 
               { text: 'Child 3', id: 'child-3', children: [ 
                  { text: 'Grandchild 1', id: 'grandchild-1' }, 
                  { text: 'Grandchild 2', id: 'grandchild-2' } 
               ]} 
            ] 
         }); 
          
         tree.setRootNode(root);
          
         tree.render(); 
      });
It shows a folder with a plus next to "My Root", but clicking it it switches to the spinning loading image but never does anything after that. There aren't any JS errors and the children are never loaded.

Thinking maybe it's just an issue with trying to stuff all that in the root before it's set as the root node, I tried this:

      Ext.onReady(function() { 
       
         var tree = new Ext.tree.TreePanel('tree'); 

         var root = new Ext.tree.TreeNode({ 
            text : 'My Root', 
            id : 'my-root'
         }); 
          
         tree.setRootNode(root);
          
         var child1 = new Ext.tree.TreeNode({ text: 'Child 1', id: 'child-1' }); 
         var child2 = new Ext.tree.TreeNode({ text: 'Child 2', id: 'child-2' }); 
         var child3 = new Ext.tree.AsyncTreeNode({ text: 'Child 3', id: 'child-3', children: [ 
                   { text: 'Grandchild 1', id: 'grandchild-1' }, 
                   { text: 'Grandchild 2', id: 'grandchild-2' } 
               ]}); 
         root.appendChild(child1, child2, child3); 

         tree.render(); 
      });
The AsyncTreeNode always ends up spinning when you try to expand it.
Reply With Quote
  #4  
Old 03-04-2007, 10:09 PM
Default

> In order to get the automated conversion of JSON to nodes, it goes through the TreeLoader

Reply With Quote
  #5  
Old 03-04-2007, 10:19 PM
Default

Ok, so the solution is to explicitly define a loader for the TreePanel.

      Ext.onReady(function() { 
       
        var tree = new Ext.tree.TreePanel('tree', {
          loader: new Ext.tree.TreeLoader()
        }); 

        var root = new Ext.tree.AsyncTreeNode({ 
          text : 'My Root', 
          id : 'my-root', 
          children: [ 
            { text: 'Child 1', id: 'child-1', leaf: true }, 
            { text: 'Child 2', id: 'child-2', leaf: true }, 
            { text: 'Child 3', id: 'child-3', children: [ 
              { text: 'Grandchild 1', id: 'grandchild-1', leaf: true }, 
              { text: 'Grandchild 2', id: 'grandchild-2', leaf: true } 
            ]} 
          ] 
        }); 
        
        tree.setRootNode(root);
        
        tree.render(); 
      });
Notice I also indicated which nodes are leaves. If you don't do that then attempting to expand a leaf node will result in a never-ending loading indicator.
Reply With Quote
  #6  
Old 03-05-2007, 08:55 AM
Default

Thanks for figuring this out Jeff/Jack. I tried 20 different ways to get this to work and, I don't think I would have ever thought to try that...

loader: new Ext.tree.TreeLoader()
Simeon
Reply With Quote
分享到:
评论

相关推荐

    android-async-http-1.4.9下载

    在Android应用开发中,网络通信是必不可少的一部分,而`android-async-http`库是一个非常流行的异步HTTP客户端库,特别适合处理与服务器的交互。这个库由Leonardo Uribe创建,它提供了简单易用的API,使开发者可以...

    mongodb-async-driver-2.0.1 jar包

    MongoDB异步驱动程序(mongodb-async-driver)是为Java开发者设计的一个库,它允许应用程序以非阻塞的方式与MongoDB服务器进行通信,提高了处理大量并发请求的能力。 在"mongodb-async-driver-2.0.1.jar"这个特定...

    android-async-http的jar包

    这些版本可能包含各种性能改进、bug修复和新功能。例如,早期版本可能解决了一些已知问题,而后期版本则可能添加了对新API或网络协议的支持。选择合适的版本取决于你的项目需求和兼容性考虑。 Android-Async-Http库...

    前端开源库-babel-helper-remap-koa2-async-to-generator

    前端开源库-babel-helper-remap-koa2-async-to-generatorbabel-helper-remap-koa2-async-to-generator,将异步函数转换为ES2015生成器(koav2->koav1)。

    You Don't Know JS- Async & Performance

    ### JavaScript异步与性能:深入理解《You Don't Know JS - Async & Performance》 #### 引言 《You Don't Know JS - Async & Performance》是一本深入探讨JavaScript中异步编程与性能优化的经典著作。本书旨在...

    vue-async-computed, Vue.js的异步计算属性.zip

    vue-async-computed, Vue.js的异步计算属性 vue-async-computed 这里插件的为Vue兼容 ! 可以使用这个插件在Vue中计算出异步计算的属性。不使用这里插件,你无法执行这里操作:new Vue({ data: { us

    You Don't Know JS- Async & Performance(O'Reilly,2015)

    Like other books in this series, You Don't Know JS: Async & Performance dives into trickier parts of the language that many JavaScript programmers simply avoid. Armed with this knowledge, you can ...

    android-async-http 源码

    Build Status ...https://github.com/loopj/android-async-http/blob/1.4.9/CHANGELOG.md Javadoc Latest Javadoc for 1.4.9 release are available here (also included in Maven repository): ...

    前端开源库-babel-plugin-transform-async-to-promises

    要使用`babel-plugin-transform-async-to-promises`,你需要安装Babel和这个插件,然后在Babel配置文件(通常是`.babelrc`或`babel.config.js`)中添加插件到转换队列。以下是一个基本示例: ```json { "plugins":...

    mongodb-async-driver-2.0.1驱动.zip

    mongodb-async-driver-2.0.1驱动文件 jar MongoDB Async Java Driver Documentation Welcome to the MongoDB Async Java driver documentation hub. Getting Started The Getting Started guide contains ...

    Android android-async-http-1.4.9

    `android-async-http-1.4.9` 是一个专为Android设计的异步HTTP库,它简化了网络请求的处理流程,使开发者能够更高效地进行网络通信。这个库由Leonard Brünings创建,并且在早期的Android开发中广泛使用。 ### 异步...

    android-async-http-master

    "Android-Async-Http"是一个流行的开源框架,专为Android平台设计,用于简化网络请求处理。这个框架的主要目标是让Android开发者能够更高效、更轻松地进行异步HTTP通信,从而获取网络数据或向服务器发送数据。在...

    前端开源库-fis-postprocessor-require-async

    在JavaScript中,`require.async`允许我们在运行时动态加载模块,而不是一次性加载所有代码。这种方式尤其适用于大型应用,可以减少首屏加载时间,提高用户体验。例如,当用户导航到某个页面时,只加载该页面所需的...

    android-async-http-1.4.11.zip

    1)包里包含android-async-http-1.4.11.jar 和 httpclient-4.5.8.jar两个文件 2)强大的网络请求库,主要特征如下: 处理异步Http请求,并通过匿名内部类处理回调结果 Http请求均位于非UI线程,不会阻塞UI操作 通过...

    swoole-2 版本.zip

    mkdir -p ~/build && \ cd ~/build && \ rm -rf ./swoole-src && \ ...tar zxvf ./tmp/swoole.tar.gz && \ ...--enable-async-redis \ --enable-sockets \ --enable-mysqlnd && \ make clean && make && sudo make install

    android-async-http官方项目

    android-async-http官方项目:来自Github; 该项目中包含了多个版本的android-async-http.jar包,目前最新版本是:android-async-http-1.4.5.jar; 地址:原项目地址:https://github.com/loopj/android-async-http

    android-async-http-1.4.8.jar

    强大的网络请求库,主要特征如下: 处理异步Http请求,并通过匿名内部类处理回调结果 Http请求均位于非UI线程,...通过线程池处理并发请求 处理文件上传、下载 响应结果自动打包JSON格式 自动处理连接断开时请求重连

    前端开源库-multihashing-async

    **前端开源库 `multihashing-async` 深度解析** 在当今的Web开发领域,前端开源库扮演着至关重要的角色,它们为开发者提供了强大的工具和功能,以提高开发效率和代码质量。`multihashing-async` 就是这样一个专为...

    android-async-http-1.4.5.jar

    最新异步网络请求android-async-http-1.4.5.jar

    android-async-http-1.4.3最新jar包

    android的异步网络加载,方便使用,免去多余的代码

Global site tag (gtag.js) - Google Analytics