Extjs 使用MixedCollection数据存储

Extjs 使用MixedCollection数据存储,extjs,grid,extjs4,store,extjs4.1,Extjs,Grid,Extjs4,Store,Extjs4.1,是否可以在ExtJS 4.1.x中执行此过程 var myMixedCollection = myStore.queryBy(...); var anotherStore = Ext.create('Ext.data.Store', { data: myMixedCollection, ... }); var myGrid = Ext.create('Ext.grid.Panel', { store: anotherStore, ... }); 因为我的网格不显示任何内容或只显示一条空行。 当

是否可以在ExtJS 4.1.x中执行此过程

var myMixedCollection = myStore.queryBy(...);
var anotherStore = Ext.create('Ext.data.Store', { data: myMixedCollection, ... });
var myGrid = Ext.create('Ext.grid.Panel', { store: anotherStore, ... });
因为我的网格不显示任何内容或只显示一条空行。

当我记录我的
myMixedCollection
时,所有数据都在这里,但当我用Firebug打开我的
另一个存储时,我可以看到我的数据存储中只有一个空行。

myMixedCollection
将是一个记录集合(模型实例)只要新店有相同的型号,这就行了!所以答案是肯定的

当然,您需要在
myMixedCollection
实例上调用

下面是一个工作示例

 // Set up a model to use in our Store
 Ext.define('Simpson', {
     extend: 'Ext.data.Model',
     fields: [
         {name: 'name', type: 'string'},
         {name: 'email', type: 'string'},
         {name: 'phone', type: 'string'}
     ]
 });

var s1 = Ext.create('Ext.data.Store', {
    model:'Simpson',
    storeId:'simpsonsStore',
    fields:['name', 'email', 'phone'],
    data:{'items':[
        { 'name': 'Lisa',  "email":"lisa@simpsons.com",  "phone":"555-111-1224"  },
        { 'name': 'Bart',  "email":"bart@simpsons.com",  "phone":"555-222-1234" },
        { 'name': 'Homer', "email":"home@simpsons.com",  "phone":"555-222-1244"  },
        { 'name': 'Marge', "email":"marge@simpsons.com", "phone":"555-222-1254"  }
    ]},
    proxy: {
        type: 'memory',
        reader: {
            type: 'json',
            root: 'items'
        }
    }
});

var mixed = s1.queryBy(function(rec){
     if(rec.data.name == 'Lisa')
         return true;
});

var s1 = Ext.create('Ext.data.Store', {
    model:'Simpson',
    storeId:'simpsonsStore2',
    fields:['name', 'email', 'phone'],
    data: mixed.getRange(),
    proxy: {
        type: 'memory',
        reader: {
            type: 'json'
        }
    }
});

Ext.create('Ext.grid.Panel', {
    title: 'Simpsons',
    store: Ext.data.StoreManager.lookup('simpsonsStore2'),
    columns: [
        { text: 'Name',  dataIndex: 'name' },
        { text: 'Email', dataIndex: 'email', flex: 1 },
        { text: 'Phone', dataIndex: 'phone' }
    ],
    height: 200,
    width: 400,
    renderTo: Ext.getBody()
});
是的,这是可能的

试试这个:

//this is the model we will be using in the store
Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'id',    type: 'int'},
        {name: 'name',  type: 'string'},
        {name: 'phone', type: 'string', mapping: 'phoneNumber'}
    ]
});

var data = new Ext.util.MixedCollection();
data.add('key1', {
    id: 1,
    name: 'Ed Spencer',
    phoneNumber: '555 1234'
});
data.add('key2', {
    id: 2,
    name: 'Abe Elias',
    phoneNumber: '666 1234'
});

//note how we set the 'root' in the reader to match the data structure above
var store = Ext.create('Ext.data.Store', {
    model: 'User',
    data : data.items,
    proxy: {
        type: 'memory',
        reader: {
            type: 'json',
            root: 'users'
        }
    }
});

store.each(function(record){
    console.log(record.get("name"));
});

​您可以在这里看到它在JSFIDLE上工作:

是的,它工作正常,我忘记了使用getRange()方法。Thx sra.Lol,这就是证据;-)+同样的答案是1。不知道你的声望是否足够,但如果你在分数上给小费,你可以看到上升/下降投票率。你的现在是1/1;)最后但并非最不重要的一点,我没有。哦,-1个巨魔又来了?这里有一个+1让它们消失:)