1. #21
    Sencha User
    Join Date
    Sep 2008
    Posts
    74
    Vote Rating
    3
    klodoma1 will become famous soon enough

      0  

    Default Why the need to define a name???

    Why the need to define a name???


    Hi guys,

    I need some ideas as I don't like the new model structure.
    WHY do we have to always define a name for a model?

    I'll put here 2 pieces of code:
    Ext4:
    Code:
    Ext.define('someModel', {
        extend: 'Ext.data.Model',
        fields: ['CHARSET', 'DESCRIPTION', 'DEFAULT COLLATION']
    });
    
    var store = new Ext.data.Store({
        model : 'someModel',
        data : [{"CHARSET":"big5","DESCRIPTION":"Big5 Traditional Chinese","DEFAULT COLLATION":"big5_chinese_ci","MAXLEN":2},{"CHARSET":"dec8","DESCRIPTION":"DEC West European","DEFAULT COLLATION":"dec8_swedish_ci","MAXLEN":1}] 
    });
    Ext3:
    Code:
    var store = new Ext.data.JsonStore({
        fields: ['CHARSET', 'DESCRIPTION', 'DEFAULT COLLATION'],
        data : [{"CHARSET":"big5","DESCRIPTION":"Big5 Traditional Chinese","DEFAULT COLLATION":"big5_chinese_ci","MAXLEN":2},{"CHARSET":"dec8","DESCRIPTION":"DEC West European","DEFAULT COLLATION":"dec8_swedish_ci","MAXLEN":1}]
     });
    At least it would be good if in the store configuration I could specify something like:
    Code:
    model: new Ext.data.Model({...})
    but it's not working.

    In my project I generate these a lot and the model is really binded to the store as the content is very dynamic.
    In ext3 this worked very well, but in ext4 I always have to give a name to the model, which... imo is not so good. It's pretty static.
    My workaround for the moment is generating model names with unique Id's but I don't like it.

    Any suggestion is very welcomed.
    Management means doing the things right,
    Leadership means doing the right things.

    www.interpid.eu, www.webdbadmin.com

  2. #22
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    9
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    Ext.define creates a class, which of course needs a name... why don't you just pass in the fields config into a store as you have in your code above?
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  3. #23
    Sencha User
    Join Date
    Sep 2008
    Posts
    74
    Vote Rating
    3
    klodoma1 will become famous soon enough

      0  

    Default


    Quote Originally Posted by edspencer View Post
    ... why don't you just pass in the fields config into a store as you have in your code above?
    Can you be more specific? I cannot follow you on this one.
    Management means doing the things right,
    Leadership means doing the right things.

    www.interpid.eu, www.webdbadmin.com

  4. #24
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    9
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    You put this under your "Ext3" snippet:

    Code:
    var store = new Ext.data.JsonStore({    fields: ['CHARSET', 'DESCRIPTION', 'DEFAULT COLLATION'],    data : [{"CHARSET":"big5","DESCRIPTION":"Big5 Traditional Chinese","DEFAULT COLLATION":"big5_chinese_ci","MAXLEN":2},{"CHARSET":"dec8","DESCRIPTION":"DEC West European","DEFAULT COLLATION":"dec8_swedish_ci","MAXLEN":1}] });
    Why don't you do this again?
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  5. #25
    Sencha User
    Join Date
    Sep 2008
    Posts
    74
    Vote Rating
    3
    klodoma1 will become famous soon enough

      0  

    Default


    Sorry maybe I was not very specific.
    I am upgrading a project from Ext3 to Ext4. If I use the ext3 example the compatibility mode is saying that is deprecated. Also in the Ext4 Documentation it is stated that JsonStore should not be used.

    In my project I generate these stores on the fly and the fields structure is dynamic, I cannot set it fixed so I had to generate always a unique model name.
    I do wonder if that is really necessary to be this way.

    I think a more simple way, would be to allow in the store configuration to specify a Model Object. It was cool in ext3 that you could create a store without the need to create other objects.

    ... or this functionality already exists in ext4 and I don't know about it.

    Regards
    Management means doing the things right,
    Leadership means doing the right things.

    www.interpid.eu, www.webdbadmin.com

  6. #26
    Sencha User
    Join Date
    Feb 2010
    Posts
    125
    Vote Rating
    3
    börn is on a distinguished road

      0  

    Default


    I'm doing something very similar here... you can make a generic model (and a generic store) without field information. Right at the time you gathered the metadata-information about the fields and validation from the server you can implement the fields into the model (by overriding the property fields of the model) ...prototype.fields = addToFieldObjectList(metadata.fields). (First you have to build up Ext.data.Field Objects from the field config and add them to a MixedCollection with a key function for field.name).
    This works quite well... but I think you have problems with associations (hasMany) if you have some... then the define-inline style of a model is quite better... but this works as well, if you give your dynamically builded models a entity-name (i think in some way those classes aren't really dynamic, if they will persist into some datasource some time?). Then you can reach those models with their names by using the modelManager.

    But i agree, it would be easier, if we have some DynamicModel Class which triggers all it's magic about associations and field registry after some hook-init-function not onExtendClass... (by default this is of course expected behaviour but in some dynamic way it's a bit..hmm laborious...).

    And besides ed is right - you can use your stores with field configurations right away - the functionality exists also I thought it's not the ext-preferred way ...

  7. #27
    Ext JS Premium Member
    Join Date
    Feb 2011
    Posts
    6
    Vote Rating
    0
    Chris.Schick is on a distinguished road

      0  

    Post Documentation needs this information

    Documentation needs this information


    Finally. After 4 days of searching I found my answer. I am loading tabs dynamically and I need to be able to deliver the tab content as JSON so setting the model on the store/proxy was giving me hell. Now that I have removed it and instead defined my fields with the store fields property all is working.

    I just wish this would be explained as a possibility in the documentation. I could have saved 3+ days.

  8. #28
    Sencha User
    Join Date
    May 2010
    Posts
    4
    Vote Rating
    0
    mickarea is on a distinguished road

      0  

    Default Dynamic Model in Extjs 4

    Dynamic Model in Extjs 4


    Hi, I'm trying to do that :

    Code:
    Ext.define('DynamicModel', {
        extend: 'Ext.data.Model',
        urlModel:"test.txt",
        fields :[],
        validations:[],
        ready:false,
        init: function(){
                        Ext.Ajax.request({
                                url: 'urlModel', 
                                success: function(response){
                                        var result=eval(response.responseText);
                                        if(result.success){
                                             for (var i = 0; i < result.fields.length; i++) {
                                                 fields[i]=result.fields[i];
                                             }
                                             for (var i = 0; i < result.validations.length; i++) {
                                                 validations[i]=result.validations[i];
                                             }
                                             ready=true;
                                        }else Ext.MessageBox.alert('error','problem occured:'+result.error); 
                                },
                                failure: function(){
                                        Ext.MessageBox.alert('error','could not connect to the server');      
                                }
                        });
        },
        isReady:function(){
            return ready;
        }   
    });
    but it doesn't work, i can't pass the field of my object to the ajax function. I would like to have some advice on how can I processed to do it ? How can I call an ajax function to modify an object ?


    Thx for ur answer.

  9. #29
    Sencha User
    Join Date
    Sep 2011
    Posts
    1
    Vote Rating
    0
    leila.carvalho is on a distinguished road

      0  

    Default


    Hi, börn!!

    I´m trying to implement something like what you did, but i´m facing many problems.

    Could you, please, send me a piece of your code?

    Thanks in advance.
    -----------------------------------
    Quote Originally Posted by börn View Post
    I'm doing something very similar here... you can make a generic model (and a generic store) without field information. Right at the time you gathered the metadata-information about the fields and validation from the server you can implement the fields into the model (by overriding the property fields of the model) ...prototype.fields = addToFieldObjectList(metadata.fields). (First you have to build up Ext.data.Field Objects from the field config and add them to a MixedCollection with a key function for field.name).
    This works quite well... but I think you have problems with associations (hasMany) if you have some... then the define-inline style of a model is quite better... but this works as well, if you give your dynamically builded models a entity-name (i think in some way those classes aren't really dynamic, if they will persist into some datasource some time?). Then you can reach those models with their names by using the modelManager.

  10. #30
    Sencha Premium Member ajaxvador's Avatar
    Join Date
    Nov 2007
    Location
    PARIS, FRANCE
    Posts
    206
    Vote Rating
    0
    ajaxvador is on a distinguished road

      0  

    Default


    hello,

    any example ?
    Vador