Esteban A. Maringolo
Esteban A. Maringolo

Reputation: 1218

Creating Ext.data.Model using JSON config

In the app we're developing, we create all the JSON at the server side using dinamically generated configs (JSON objects). We use that for stores (and other stuff, like GUIs), with a dinamically generated list of its data fields.

With a JSON like this:

{
"proxy": {
    "type": "rest",
    "url": "/feature/163",
    "timeout": 600000
},
"baseParams": {
    "node": "163"
},
"fields": [{"name": "id", "type": "int" },
    {"name": "iconCls", "type": "auto"},
    {"name": "text","type": "string"
    },{ "name": "name", "type": "auto"}
    ],
"xtype": "jsonstore",
"autoLoad": true,
"autoDestroy": true
}, ...

Ext will gently create an "implicit model" with which I'll be able to work with, load it on forms, save it, delete it, etc.

What I want is to specify through a JSON config not the fields, but the model itself. Is this possible?

Something like:

{
model: {
       name: 'MiClass',
       extends: 'Ext.data.Model',
       "proxy": {
    "type": "rest",
    "url": "/feature/163",
    "timeout": 600000},
        etc... }
"autoLoad": true,
"autoDestroy": true
}, ...

That way I would be able to create a whole JSON from the server without having to glue stuff using JS statements on the client side.

Best regards,

Upvotes: 0

Views: 1148

Answers (2)

Esteban A. Maringolo
Esteban A. Maringolo

Reputation: 1218

There's no way to achieve what I want. The only way you can do it is by means of defining the fields of the Ext.data.Store and have it to generate the implicit model by using the fields configuration.

Upvotes: 0

dbrin
dbrin

Reputation: 15673

I don't see why not. The syntax to create a model class is similar to that of store and components:

Ext.define('MyApp.model.MyClass', {
    extend:'Ext.data.Model',
    fields:[..]
});

So if you take this apart you could call Ext.define(className,config); where className is a string and config is a JSON object and both are generated on the server.

Upvotes: 1

Related Questions