2013-11-05 27 views
1

假設柵陣列如果我創建了一個格子店這樣如何找到在瀏覽器ExtJS的

var store = Ext.create('Ext.data.ArrayStore', { 
fields:['id','title', 'director', 'released', 'genre','tagline', 'price', 'available'], 
data: [ 
     [ 
      1, 
      "Office Space", 
      "Mike Judge", 
      "1999-02-19", 
      1, 
      "Work Sucks", 
      "19.95", 
      1 
     ], 
     [ 
      3, 
      "Super Troopers", 
      "Jay Chandrasekhar", 
      "2002-02-15", 
      1, 
      "Altered State Police", 
      "14.95", 
      1 
     ] 
    ] 
}); 

當我在瀏覽器中運行它,我看不到任何東西,因爲它已經被保存在瀏覽器的內存,我們需要將其顯示到網格上以查看這些數據。

如果我使用編輯器插件在瀏覽器中編輯網格,那麼我如何才能看到對網格存儲所做的更改?如何看到它?

回答

1
  1. 您可以將storeId添加到商店,然後您可以使用以下全局功能: Ext.StoreManager.lookup('storeId'); 具有此功能你可以隨時從任何地方購買商店。

  2. 網格面板有edit(editor, e, eOpts)事件,它可以在編輯完成後使用。

例子:

var store = Ext.create('Ext.data.ArrayStore', { 
    storeId: 'gridStore', 
    (...) 
}); 

var grid = Ext.create('Ext.grid.Panel', { 
    store: store, 
    (...), 
    listeners: { 
     edit: function(editing, e, eOpts) { 
      var record = e.record; 
      console.log('Changes on this record: ', e.record.getChanges());   
      console.log('Original value: ', (editing.ptype == 'cellediting' ? e.originalValue : e.originalValues)); 
      console.log('New value: ', (editing.ptype == 'cellediting' ? e.value : e.newValues));   
     } 
    } 

}); 

//for save on a toolbar 
var button = Ext.create('Ext.button.Button', { 
    text: 'Save', 
    (...), 
    handler: function() { 
     var gridStore = Ext.StoreManager.lookup('gridStore'); 
     console.log('all added, but not synchronized records: ', gridStore.getNewRecords()); 
     console.log('all edited, but not synchronized records: ', gridStore.getUpdatedRecords()); 
     console.log('all modified(added and edited), but not synchronized records:', gridStore.getModifiedRecords()); 
     console.log('all removed, but not synchronized records:', gridStore.getRemovedRecords()); 
    } 
});
+0

感謝@alexander它的工作原理 – insanity

1

我想說這取決於。

首先,顯示你在網格存儲,它應該是這樣的(簡體),以下代碼:

var grid = Ext.create('Ext.grid.Panel', { 
    title: 'Test', 
    store: store, 
    columns: [ 
     { text: 'title', dataIndex: 'title' }, 
     { text: 'director', dataIndex: 'director', flex: 1 } 
    ], 
    height: 200, 
    width: 400 
}); 
var MyWindow = Ext.create('widget.window',{width:400,height:200,items:[grid]}); 
MyWindow.show(); 

你分配你的店給本地變量「存儲」。通常情況下,如果您在網格中使用該商店,並且您在該網格中進行更改,則應該在商店中反映出來。

當你把它編輯與編輯網格插件,更改直接writen在店裏,所以這應該工作:

var currentStoreContent = store.data.items; 

,或者從電網:

var currentStoreContent = grid.getStore().data.items 
+0

我怎麼能看到它在瀏覽器?這些更改實際上保存在瀏覽器內存中,因此有什麼方法可以查看這些數據 – insanity