Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs 4 - create new empty Record from Store without Model

I have tried to create a new empty record without creating a model.

Accidentally I tried to run this:

new new storeComp.model()

and it actually works!

anyone know any solution for this or an answer to how is it working ?

Thanks! Shalev

like image 655
Shalev Shalit Avatar asked Jul 11 '26 07:07

Shalev Shalit


2 Answers

Stores that are not configured with a model will create an anonymous one implicitly. This is explained in the docs for the implicitModel private property (the store needs to know that because if it uses an implicit model, it must destroy it when it is itself destroyed).

In the end that means that you can safely expect any store to be backed with a model.

like image 83
rixo Avatar answered Jul 14 '26 12:07

rixo


I faced the same problem for an associative store. For that i have used below JSON format to load project store. So automatically empty record is created in associative (project-resources) Store.

Store:

Ext.define('App.store.Projects', {
   extend : 'Ext.data.Store',
   model : 'App.model.Project'
});

Models:

Ext.define("App.model.Project", {
    extend: 'Ext.data.Model',
    idProperty : 'id',
    uses : ['App.model.ProjectResource'],
    fields: [
        { type: 'auto', name: 'id'},
        { type: 'number', name: 'customerid'},
        { type: 'string', name: 'projectcode'}
    ],
    associations: [
    {type: 'hasMany', model: 'App.model.ProjectResource', name: 'Resources', storeConfig: { remoteFilter: true }}
    ]
});

Ext.define("App.model.ProjectResource", {
    extend: 'Ext.data.Model',
    idProperty : 'id',
    fields: [
        { type: 'number', name: 'id'},
        { type: 'string', name: 'name'},
        { type: 'number', name: 'projectid'},
        { type: 'auto', name: 'resourceid'}
    ],

    associations : [
    {type : 'belongsTo', model: 'App.model.Project'}
    ]
});

JSON Format:

 [
        {
            "id": "105",
            "customerid": "105",
            "projectcode": "ALN01",
            "Resources": {}
        }
]

Loading store with empty object (like "Resources": {}) will create empty model.

like image 26
Sivakumar Avatar answered Jul 14 '26 13:07

Sivakumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!