2013-11-05 80 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