-1

当视图被带入视口时,我希望能够加载存储并将检索到的模型设置到视图中的表单上。但是,我不太确定我应该为此目的使用哪个事件。

这是否应该在视图的“Painted”事件中完成,视图是否应该返回到控制器,然后填充视图,或者是否有其他推荐的方法?

目前在我看来有这个:

  listeners: {
        painted: function () {
            var contactStore = Ext.getStore("theContactDetailsStore");

             contactStore.load({
                    scope: this,
                    callback: function (record, operation, success) {
                        if (success && record[0]) {                            
                            this.setRecord(record[0]);                                     
                        }
                    }
                });
       }
   }
4

2 回答 2

0

绘制事件应该用于执行一些低级别的 DOM 操作,如修复元素大小、位置等。这是我建议你的:

  • 首先加载商店,最终在之前用“正在加载...”消息掩盖视口,这样如果操作需要时间,用户就不会觉得应用程序崩溃了。
  • 在商店“加载”回调中显示您的表单视图,将所需数据模型作为“记录”配置参数传递。

通过这种方式,您的表格将立即显示为您的记录数据。

PS:如果您在加载商店之前屏蔽视口,请记住在显示表单之前在“加载”回调中取消屏蔽它。

于 2012-12-29T14:08:06.827 回答
0

有两种方法可以处理这个问题:

  1. Create view first and in its initialize function create & load store. The code for creating an loading could easily be part of controller by firing corresponding event from initialize. This might look ugly because your view might not look good without data , but still this would be faster so please take care of masking & unmasking(in load callback of store) the view.

  2. Create your store first and in its load callback fire the event with data(store records etc) which will create the view using that data. This would look slow initially because you won't see any part of view until store is loaded.

于 2012-12-30T04:47:13.317 回答