-
22 Jan 2012 11:37 AM #21
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:
Ext3: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}] });
At least it would be good if in the store configuration I could specify something like: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}] });
but it's not working.Code:model: new Ext.data.Model({...})
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
-
22 Jan 2012 12:07 PM #22Sencha - Community Support Team
- Join Date
- Jan 2009
- Location
- Palo Alto, California
- Posts
- 1,941
- Vote Rating
- 6
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
-
22 Jan 2012 12:16 PM #23Management means doing the things right,
Leadership means doing the right things.
www.interpid.eu, www.webdbadmin.com
-
22 Jan 2012 12:19 PM #24Sencha - Community Support Team
- Join Date
- Jan 2009
- Location
- Palo Alto, California
- Posts
- 1,941
- Vote Rating
- 6
You put this under your "Ext3" snippet:
Why don't you do this again?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}] });Ext JS Senior Software Architect
Personal Blog: http://edspencer.net
Twitter: http://twitter.com/edspencer
Github: http://github.com/edspencer
-
22 Jan 2012 1:19 PM #25
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.
RegardsManagement means doing the things right,
Leadership means doing the right things.
www.interpid.eu, www.webdbadmin.com
-
25 Jan 2012 11:03 PM #26
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
...
-
3 Mar 2012 4:01 AM #27
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.
-
7 Mar 2012 6:36 AM #28
Dynamic Model in Extjs 4
Dynamic Model in Extjs 4
Hi, I'm trying to do that :
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 ?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; } });
Thx for ur answer.
-
11 May 2012 11:11 AM #29
-
18 May 2012 5:15 AM #30
hello,
any example ?Vador


Reply With Quote