0

I have data store "a" with hasMany attribute,trying to create new store "b" by copying hasMany records of "a" with below code,but when i use b store for combo box it throws error saying record.length is undefined

var b = Ext.create("Ext.data.store"{
model:'service'});
Ext.getStore("a").each(function(record,id){
for(var i in record){
b.add(record.raw.subservice);
}
})
Tarabass
  • 3,132
  • 2
  • 17
  • 35

2 Answers2

0

It works for me, try this. I hope it helps.

function deepCloneStore (source) {
    var target = Ext.create ('Ext.data.Store', {
        model: source.model
    });
    Ext.each (source.getRange (), function (record) {
        var newRecordData = Ext.clone (record.copy().data);
        var model = new source.model (newRecordData, newRecordData.id);
        target.add (model);
    });
    return target;
}

Original source code reference.

Community
  • 1
  • 1
Vishal Zanzrukia
  • 4,902
  • 4
  • 38
  • 82
0

You are trying to iterate store, instead you need to iterate store.data.items. And you do not need for cycle for record. Try this

var b = Ext.create("Ext.data.store"{
    model:'service'
});
Ext.getStore("a").data.items.each(function(record,id){
    //You can add multiple records by calling .add method once
    b.add(record.data.subServiceItems);
});

Write if this does not help.

Zura Sekhniashvili
  • 1,147
  • 7
  • 19