3

I would like to dynamically define models to handle data from a data store. I have a web service that returns different JSON structures (eg. field_1:"val1" or field_1:"val1 field_2:"val2" or field_1:"val1"...field_n:"valn"). I've seen that for using

Ext.regStore("UserStuffStore",{
        model: "myModel",
        proxy: {
            type: 'ajax',
            url: rl,
            headers: {
                'Accept' : 'application/json'
            },
            reader: {
                type: 'json'
            }
        },
        autoLoad: true
    });

I need to specify a model. In this case, I need to see data structures before defining the model. How can I solve it?

Surely I can make two different calls to the web service (the first to get the data structures, the other to get data), is there another way?

1 Answer 1

1

Not tested. I hope it helps:

var fields = [{
    name: 'id',
    type: 'int',
    useNull:true
}]; //this can be obtained dynamically

var model = {
    extend: 'Ext.data.Model',
    fields: fields
};

Ext.define(name, model);

Also see: Sencha forum

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.