ExtJS 4:在存储加载回调函数中存储未填充数据的数据 [英] ExtJS 4: Store data not populated with data inside store load callback function

查看:164
本文介绍了ExtJS 4:在存储加载回调函数中存储未填充数据的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么records.length设置为大于0的数字,但store.data.length等于0?我基本上试图引用我的存储内部的回调,以便我的网格有数据,然后我将它添加到我的形式。但是存储数据由于某种原因不存在。如果你有一个更好的方法实现相同的最终结果,我愿意改变它的建议。基本上,每个网格都是基于与此代码的包装循环不同的过滤器动态构建的。

Why would records.length be set to a number greater than 0, but the store.data.length is equal to 0? I'm basically trying to reference my store inside of the callback, so that my grid has data before I add it to my form. But the store data doesn't exist for some reason. If you have a better way of achieving the same end result, I'm willing to change it to your suggestion. Essentially, each grid is dynamically built based on different filters from the wrapping loop of this code.

                            var p = item.get('p');
                            var store = Ext.create('App.store.example.MyStore');
                            store.clearFilter(true);
                            store.filter('s', s);
                            store.filter('p', p);

                            store.load({

                                callback: function(records, operation, success) {
alert(store.data.length);
alert(records.length);
                                    var grid = Ext.create('App.view.example.MyGrid', {
                                        store: store
                                    });

                                    formPanel.add(
                                        Ext.create('Ext.form.FieldSet', {
                                            id: p + '_TOP',
                                            title: p,
                                            width: '100%',
                                            anchor: '100%',
                                            layout: {
                                                type: 'vbox',
                                                align: 'stretch'
                                            },
                                            items: [myGrid]
                                        })
                                    );
                                    formPanel.doLayout();


                                }
                            });

                            formPanel.doLayout();
                        });


推荐答案

我想如果我只设置remoteFilters 真的,它会工作。

I think if I would have just set the "remoteFilters" to true, it would have worked.

但我简化了一下。我设置过滤器在商店创建配置。而且不得不在我的模型里面设置两个配置来让这个工作。这样,我不必手动设置过滤器,或执行加载(因为我有存储autoLoad它为我)。

But I simplified it a bit. I set the filters inside the store create configs. And had to set two configs inside my model to get this to work. This way, I didn't have to set the filters manually, or perform the load (because I have the store autoLoad it for me).

查看代码:

View code:

                        var store = Ext.create('App.store.example.MyStore', {
                            filters: [{
                                property: 's',
                                value: s
                            },{
                                property: 'p',
                                value: p
                            }]
                        });

                        var grid = Ext.create('App.view.example.MyGrid', {
                            store: store
                        });
                        formPanel.add(
                            Ext.create('Ext.form.FieldSet', {
                                id: p + '_TOP',
                                title: p,
                                width: '100%',
                                anchor: '100%',
                                layout: {
                                    type: 'vbox',
                                    align: 'stretch'
                                },
                                items: [grid]
                            })
                        );

存储配置:

autoLoad: true,
remoteFilter: true,

这篇关于ExtJS 4:在存储加载回调函数中存储未填充数据的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆