ExtJs 4 - 如何在动态更新 closable 属性 时更新 Ext.window.Window 布局?

ExtJs 4 - How to update Ext.window.Window layout when closable property was updated dinamically?

我遇到了主题中描述的问题。 我有 ExtJs 应用程序。我的任务显示带有填充网格的弹出窗口 window。 默认 window.closable = false;

我在控制器的某处定义了 window,它看起来像这样:

Ext.define('Return.controller.ViewportController', {
  extend: 'Ext.app.Controller',
  views:[
    'ModalWindow',
    'ProductsList'
  ],

  stores:[
    ...,
    'ProductsStore'
  ],

  models:[
    ...,
    'ProductsModel'
  ],


  resultWindow: Ext.create('Ext.window.Window', {
    itemId: 'popupWindow',
    id: 'popupWindow',
    title: 'Result List',
    layout:'fit',
    width: 900,
    height: 600,
    modal: true,
    closable: false,
    closeAction: 'hide',
    items:[]
  })


  onPopupShow: function() {
    // first add grid with store to popup window;
    // then need to load data into ProductsStore;
    // depending on values in store_stock column need to define
    // if I should show close button for Window or not.
    // By default button is invisible
    var prodStore = Ext.getStore('ProductsStore');
    this.resultWindow.add({xtype: 'ProductsList', border: true});
    prodStore.load({
      params: {
        stock_locations_id: 1,
        query: value
      },
      callback: function (result) {
        var app = this;
        if (result.length > 0) {
          //make window closable
          app.resultWindow.closable = (!prodStore.sum('stock'));
          //show and update Layout
          app.resultWindow.show().updateLayout();
          Ext.getCmp('ProductsList').getView().refresh();
          return;
        }
        //do smth else
      }, scope: this
    });
  }
);

用户应执行以下操作: 在 popupShow 上找到网格中的任何行,单击它。之后,弹出窗口将被隐藏,所选行将与所有数据一起添加到父网格。

prodStore.sum('stock') 时工作正常 - 表示列中所有值的总和大于零。 当 'stock' 列中的所有值都为零时,用户应该能够关闭 window.

当我调试那段代码时,window closable 属性 变为 true 并且可以显示。但在正常情况下 运行 - 没有。 同时尝试检查控制台 Ext.getCmp('popupWidow').closable 它 returns true 根据我的需要。

我想应该更新布局。我在 window 显示后立即执行此操作。但很遗憾。

这里还有什么其他方法适用?

提前致谢。

callback函数中创建resultWindow对象并在初始化时设置closable属性。

所以,你可以这样做:

Ext.define('Return.controller.ViewportController', {
  extend: 'Ext.app.Controller',

  ...

 resultWindowConfig: {
   itemId: 'popupWindow',
   id: 'popupWindow',
   title: 'Result List',
   layout:'fit',
   width: 900,
   height: 600,
   modal: true,
   closable: false,
   closeAction: 'hide',
   items:[]
 },

 onPopupShow: function() {
   ...
   scope: this,
   callback: function (result) {
     var app = this;
     if (result.length > 0) {
      //make window closable
      app.resultWindowConfig.closable = (!prodStore.sum('stock'));

      var resultWindow = Ext.create('Ext.window.Window', app.resultWindowConfig);

      //If you want to set resultWindow as a property of the app object just do app.resultWindow = resultWindow;
      resultWindow.show();

      ...
      return;
     }
  });
});

如果你查看 Ext.window.Window 文档,你可以看到这个 属性 没有设置函数,这意味着你不能更新 UI改变这个 属性.