-
14 Jan 2013 5:07 PM #1
Polymorphic model?
Polymorphic model?
I have a textbook case of polymorphism: my web server is going to return a shape which could be a circle (center point + radius), rectangle (upper left/lower right), polygon (arbitrary list of points), etc. What's the best way to handle this from a model standpoint?
I'm using an ajax proxy. One solution is to define a model object which is the union of all fields and includes a string that identifies the shape type. It would work ... but I was hoping ExtJS offered a better solution. (I just don't see how to choose a different model based on the server's response.)
-
15 Jan 2013 7:15 AM #2
I think something like this should work
I think something like this should work
Code:Ext.define('Sample.model.Shape', { extend : 'Ext.data.Model', fields : [ {name: 'id', type: 'int'}, {name: 'name', type: 'string'} ] }); Ext.define('Sample.model.Circle', { extend : 'Sample.model.Shape', fields : [ {name: 'radius', type: 'float'} ] });
-
16 Jan 2013 1:29 AM #3
Probably I would try to use extjs's associations in direction of polymorphic associations, by default is nothing implemented, and probably you will have to extend the reader in order to create the right model based on server response.....could be an idea which worths to try.
I didn't look well, to comment if their implementations are good or not, but you may get some inspirations from this guys:
http://extjs-tutorials.blogspot.com/...-subclass.html
https://github.com/opennode/opennode...&-Partitioning
-
16 Jan 2013 1:58 AM #4
-
16 Jan 2013 10:04 AM #5
Thanks vadimv, that's pretty much what I was looking for. It's a shame that ExtJS doesn't offer this functionality natively.


Reply With Quote