0

我使用 Ext Js 4,里面有一个标签面板和标签。我已设法添加新选项卡并防止添加已打开的相同选项卡。无论如何,数据在第一次打开后列出,但在重新打开后无法列出。我认为 Ext Js 4 存在与在数据网格上列出数据相关的问题。你能就这个问题提供一个建议和样本吗?提前致谢...

4

1 回答 1

0

Based on your question it sounds like you have a gridpanel inside of a tabpanel:

Anyhow, the data is listed after first opening, but cannot be listed after reopening. I think there is a problem with Ext Js 4 related to listing data on datagrid.

When you first open your tab the gridpanel has data in it, then when you close it and reopen it there is no data. Correct me if I have this wrong.

That would be normal ExtJS behavior if you are creating the datastore for your gridpanel separate from the code that creates the gridpanel.

When you close your gridpanel tab (destroying it), it will also destroy the store that holds the data for it.

There are a few solutions, you can give your store a storeId config which will register it with StoreManager and keep it from getting destroyed when a component is destroyed. Using this method you can also configure your gridpanel with the store like this:

// other grid configs...
store: Ext.StoreManager.lookup('yourStoreId'),
// other grid configs...

That method will not reload the store data when you create a new gridpanel tab. If you actually want the store to load new data whenever you create a new tab you should simply include your store creation code - Ext.create(Ext.data.Store, { //etc.. (or however you are doing it) with the same code that is creating the gridpanel tab.

With that second method, your gridpanel will continue to destroy its datastore whenever it closes - the way it is doing now, but you will recreate and reload the store whenever you create a new tab so it will not be a problem.

I think there is also a config somewhere that lets you specify if you want the gridpanel to destroy the store when it is destroyed itself.

I usually use the first method however, then I destroy the store manually when I really don't need it anymore. Or reload the data manually when I want that. It helps cut down on unnecessary Ajax requests on the server.

于 2012-08-18T15:37:55.557 回答