3

I dynamically create my store from a model relation and attach this store to a grid.

var map = record.getCommunity().mappings();

map.load({
    url: '/myUrl/mappings',
    scope: this,
    callback: function(records, operation, success) {

        map.group('type');

        //ExtJS bug https://www.sencha.com/forum/showthread.php?265674

        me.getOutgoingGrid().destroy();

        childGrid = Ext.create('hds.view.outgoingGrid', {
            store: map
        });
        me.getGridHolder().add(childGrid);
        me.getOutgoingGrid().getSelectionModel().select(0, false) ;
    }
});

When I want to create a new model instance and insert it into this dynamic store I get the following error:

Cannot read property 'isModel' of undefined

Here is the code that triggers the error:

var newMap = Ext.create('hds.model.MappingModel', {
    indetifier  : "something",
});

me.getOutgoingGrid().store.insert(0, newMap);

I cannot found the reason of this problem....Any ideas?

Jacob
  • 3,580
  • 22
  • 82
  • 146
  • Can you provide a working fiddle with the error? Which ExtJs version are you using? – And-y Sep 14 '15 at 07:39
  • 4
    -1 upvoting this just feels like abusing SO to me. Who can be genuinely interested in this question that is only about debugging your code? You don't give the version of the lib you're using, not even the major number, even though you've been asked for. You don't give the line number of the error either, so answering this can only be a **huge** guess, and those who tries get downvoted. Please review SO policies, they specifically require to provide a working example to ask help for debugging. – rixo Sep 14 '15 at 18:34
  • indentifier instead of "indetifier" in your model creation ? – Benoit Cuvelier Sep 15 '15 at 12:47
  • I mean identifier ...and you wrote "indetifier" – Benoit Cuvelier Sep 16 '15 at 08:24

4 Answers4

5

It is hard to know what is breaking your code but here are a couple of things:

1 - You need to define the model identifier in the class prototype not in the instance.

2 - You misspelled identifier

So your model should look like:

Ext.define('hds.model.MappingModel', {
    identifier  : "something",
});

var newMap = new hds.model.MappingModel({
    //...your config here
});

The error that you are seeing Cannot read property 'isModel' of undefined is thrown when the store tries to check if model is an instance of Ext.data.Model but the model being passed is undefined. This can happen for several reasons but usually it's because you are trying to create a model before the prototype has been defined or because there is a typo on your code.

Please, try creating a a fiddle (https://fiddle.sencha.com) reproducing this error or it will be very hard to help you.

Regards,

Guilherme Lopes
  • 4,688
  • 1
  • 19
  • 42
2

If there was an fiddle, It would be more helpful. As I understand from your question, you have some data and you can't set the data to store or model correctly. If you had defined your model or store before set to grid, there would not be a problem. I added a fiddle how model proxy works with store and etc. Hope it helps. If the fiddle does not explain your problem, please change the fiddle codes. So, we can understand what your problem exactly. Here is the fiddle: https://fiddle.sencha.com/#fiddle/tvq

            Ext.define('model.Users', {
                extend: 'Ext.data.Model',
                fields: [
                    { name: 'Name',                     type: 'string'},
                    { name: 'City',                     type: 'string'},
                    { name: 'Country',                  type: 'string'},
                ],
                //idProperty: 'Name',
                proxy: {
                    type: 'ajax',
                    rootProperty: 'records',
                    rootUrl: 'users', // used when updating proxy url
                    url: 'users',
                    reader: {
                        type: 'json',
                        rootProperty: 'records'
                    }
                }

            }); //model


            var modelExt = Ext.create('model.Users', { Name: 'Ernst Handel'});
            var storeExt = Ext.create('Ext.data.Store', {
                requires: 'model.Users',
                model: 'model.Users'
            });
            modelExt.load({
                scope: this,
                success: function(record) {
                    var colObjects = [];
                    Ext.each(Object.keys(record.data), function(key) {
                        colObjects.push({
                            text: key,
                            dataIndex: key
                        });
                    });

                    storeExt.loadData([record]);
                    //console.log(record, storeExt);
                    var grid = Ext.create('Ext.grid.Panel', {
                        store: storeExt,
                        columns: colObjects,
                        renderTo: Ext.getBody()
                    });
                },
                failure: function (err) {

                }
            });
Semih Gokceoglu
  • 1,408
  • 1
  • 13
  • 21
0

Create model like this and then use.

var newMap = Ext.create('Ext.data.model', {
    identifier  : "something"
});
Mohit Saxena
  • 1,439
  • 1
  • 12
  • 21
0

Add a new file in Model folder named like MappingModel.js and define model like this.

Ext.define('hds.model.MappingModel', {
extend: 'Ext.data.Model',
fields: [
  'something'
]
});

Add this in app.js and then use MappingModel in your dynamic store.

Mohit Saxena
  • 1,439
  • 1
  • 12
  • 21