ExtJS 4.2 - 使用当前变量存储刷新网格

时间:2017-01-31 12:27:46

标签: javascript extjs

我在面板窗口上有一个加载某个商店的网格面板:

xtype: 'gridpanel',
  store: custStore,
  viewConfig: {
    loadMask: false,
    enableTextSelection: true
  },
  hideHeaders: false,
  bodyBorder: true,
  id: 'playerslist-grid-id',
  itemId: 'playerslist-grid-id',
  viewConfig: {
    deferEmptyText: false,
    emptyText: 'No records yet'
  },
  columns: [{
    text: 'Customer',
    dataIndex: 'username',
    flex: 1
  }, {
    header: '',
    xtype: 'actioncolumn',
    itemId: 'remove-player-btn',
    width: 50,
    sortable: false,
    resizable: false,
    menuDisabled: true,
    hidden: bHide,
    items: [{
      icon: 'resources/img/x.png',
      tooltip: 'Remove Player',
      scope: oMe
    }],
    editor: {
      xtype: 'text',
      name: 'deleteRow'
    }
  }]

custStore变量的处理方式如下。

var oMe = this;
oController = EcommBackoffice.Global.app_var.getController('CustomerTagsController'),
  cStore = oController.getCustomerListStore(),
  cDetails = cStore.first(),
  customers = [];

customers = cDetails.get('customers');

var custStore = Ext.create('Ext.data.ArrayStore', {
  model: 'CustomerList',
  data: customers
});

我需要将它放在数组存储中,因为数据对象是这样嵌套的:

{
  id: 1,
  name: 'test',
  description: 'test',
  customers: [{
    id: 001,
    username: 'bob'
  }, {
    id: 001,
    username: 'terese'
  }, {
    id: 001,
    username: 'dab'
  }, {
    id: 001,
    username: 'bba'
  }, {
    id: 001,
    username: 'hello'
  }]
}

在我的控制器上,我处理了一个函数custStorerequest之前的其他参数。

click: function() {
  oController.addPlayerToTag(newPlayer, tagId, custStore);
}

问题:成功回拨后,如何在custStore上重新加载gridpanel?我尝试使用custStore.load()但没有发生任何事情。

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您将从服务器返回一个新的客户数组,并需要使用该数组刷新网格。在这种情况下,我认为你需要在custStore上调用setData,传递新的客户数组。不确定4.2是否有这种方法。如果没有,请尝试设置custStore.data属性。

如果仅此方法无效,请尝试在网格上调用reconfigure,然后传入custStore。