【问题标题】:ExtJs 4 - How to update Ext.window.Window layout when closable property was updated dinamically?ExtJs 4 - 如何在动态更新可关闭属性时更新 Ext.window.Window 布局?
【发布时间】:2015-10-26 16:48:09
【问题描述】:

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

在控制器的某个地方我定义了窗口,它看起来像这样:

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 将 closable 属性设置为 true 并且可以显示。但在正常运行中 - 不。 在尝试签入控制台Ext.getCmp('popupWidow').closable 的同时,它会根据我的需要返回true

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

这里还有什么适用的方式?

提前致谢。

【问题讨论】:

    标签: javascript extjs extjs4


    【解决方案1】:

    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。

    【讨论】:

    • 嗯,也许你是对的。当然,我阅读了文档,是的,该属性没有设置器。我会尝试应用您的解决方案并告知结果。我认为,它应该有所帮助。
    • 是的,它对我有用。在这种情况下它会更好,因为我们每次在加载结果产品列表时都会创建这个窗口。因此不会存储以前的设置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 2014-04-06
    • 2020-02-29
    • 2013-06-19
    • 1970-01-01
    相关资源
    最近更新 更多