ext treestore auload失效问题


Forum  /  Ext JS Community Forums 4.x  /  Ext: Q&A  /
  1. #1
    Sencha User fabio.policeno's Avatar
    Join Date
    Sep 2010
    Location
    Curitiba - PR / Brasil
    Posts
    214
    Vote Rating
    0
    Answers
    8
    fabio.policeno is on a distinguished road

      0  

    Unanswered: autoLoad: false TreeStore in with TreePanel rootVisible: false


    Hello, I understand the idea of ​​autoLoad: false TreeStore the "no work" or work differently due to the expansion of the root. But if you do not want to display this root, there's no way I set it so that it is not expanded, since it is hidden. The main problem is I need to load the tree after it is rendered, but it strikes me the following error:

    Code:
    records[i] is undefined
    ...
    ns[i].viewRecordId = records[i].internalId;
    Moreover, it tries to create new nodes instead of removing the existing and doing a "reload" menu.To better illustrate the problem, I created the example below.

    Code:
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <link rel="stylesheet" href="../resources/css/ext-all.css" type="text/css">
            <script type="text/javascript" src="../ext-all-dev.js"></script>
            <script type="text/javascript">
    
                Ext.define('Menu', {
                    extend: 'Ext.data.Model',
                    fields: [
                        {name: 'id', type: 'int'},
                        'text',
                        'leaf'
                    ],
                    proxy : {
                        type  : 'ajax',
                        url      : 'menu.json',
                        reader: {type: 'json'},
                    }
                });
            
                Ext.onReady(function() {
                    var store = Ext.create('Ext.data.TreeStore', {
                        model    : 'Menu',
                        autoLoad: true
                    });
    
                    Ext.create('Ext.tree.Panel', {
                        renderTo   : Ext.getBody(),
                        height       : 100,
                        store       : store,
                        rootVisible: false
                    });
                    
                    store.load();
                });
            </script>
        </head>
        <body>
        </body>
    </html>
    menu.json
    Code:
    [{
        id    : 1,
        text: 'Menu 1',
        leaf: true
    },{
        id    : 2,
        text: 'Menu 2',
        leaf: true
    }]
    Ext JS 4.0.7

    Thank you!
  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    27,805
    Vote Rating
    325
    Answers
    2533
    mitchellsimoens has much to be proud of  mitchellsimoens has much to be proud of  mitchellsimoens has much to be proud of  mitchellsimoens has much to be proud of  mitchellsimoens has much to be proud of  mitchellsimoens has much to be proud of  mitchellsimoens has much to be proud of  mitchellsimoens has much to be proud of  mitchellsimoens has much to be proud of

      0  


    If you wanted to stop the loading you can return false in a beforeload event listener. Then to load you can do

    Code:
    store.load({
        node : rootnode
    });
    Mitchell Simoens
    Sencha Inc, Senior Forum Manager
    @SenchaMitch

    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Want to learn Sencha Touch 2? Check out  Sencha Touch in Action that is in heavy development! Several chapters already available!
  3. #3
    Sencha User fabio.policeno's Avatar
    Join Date
    Sep 2010
    Location
    Curitiba - PR / Brasil
    Posts
    214
    Vote Rating
    0
    Answers
    8
    fabio.policeno is on a distinguished road

      0  


    As specifically stop load? return false just before the load is not going to stop .. I do not understand your code .. I put in the rootnode, if I do not want the menu has a root?
  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    27,805
    Vote Rating
    325
    Answers
    2533
    mitchellsimoens has much to be proud of  mitchellsimoens has much to be proud of  mitchellsimoens has much to be proud of  mitchellsimoens has much to be proud of  mitchellsimoens has much to be proud of  mitchellsimoens has much to be proud of  mitchellsimoens has much to be proud of  mitchellsimoens has much to be proud of  mitchellsimoens has much to be proud of

      0  


    Code:
    store.on('beforeload', function() { return false; });
    then...

    Code:
    store.load({
        node : store.getRootNode()
    });
    Mitchell Simoens
    Sencha Inc, Senior Forum Manager
    @SenchaMitch

    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Want to learn Sencha Touch 2? Check out  Sencha Touch in Action that is in heavy development! Several chapters already available!
  5. #5
    Sencha User fabio.policeno's Avatar
    Join Date
    Sep 2010
    Location
    Curitiba - PR / Brasil
    Posts
    214
    Vote Rating
    0
    Answers
    8
    fabio.policeno is on a distinguished road

      0  


    Code:
    Ext.define('Compstoque.view.Menu' ,{
        extend       : 'Ext.tree.Panel',
        alias      : 'widget.mainmenu',
        region     : 'west',
        title       : 'Menu',
        width       : 200,
        minWidth   : 150,
        maxWidth   : 400,
        split       : true,
        collapsible: true,
        store       : 'Menu',
        rootVisible: false
    });
    Code:
    Ext.define('Compstoque.store.Menu', {
        extend: 'Ext.data.TreeStore',
        model : 'Compstoque.model.Modulo'
    });
    Code:
    ...
    'mainmenu'          : {
                    render     : me.loadMenu,
                    ...           
     },
    ...
    loadMenu: function(tree) {
            var store = tree.getStore();
            
            store.on('beforeload', function() {return false;});
            store.load({
                node : store.getRootNode()
            });
        },
    not really loads the menu, but he keeps doing the requests, including a need to "reload" on the menu with other data, but is not occurring. Even several requests being made unnecessarily. In short, I want to load the menu in store only at render, this method LoadMenu, but I'm not getting.

    store.jpg
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值