1. #1
    Sencha User jaadolio's Avatar
    Join Date
    Nov 2010
    Posts
    18
    Answers
    1
    Vote Rating
    0
    jaadolio is on a distinguished road

      0  

    Default Answered: ExtJS 4 MVC Issue loading multiple Model Instances

    Answered: ExtJS 4 MVC Issue loading multiple Model Instances


    Good Morning, I have a problem regarding ExtJS MVC architecture. Instead of creating a Main Viewport as the main interface for all my views, I decided to implement different views that are being generated dinamically (using Ext.create(...)) depending on which option the user selects. I am also using a little bit of jQuery as a way to manage easily some special events that involve removing particular elements from a webpage (like DIVs that I remove and create dinamically in order to avoid page loading, so that later I can instantiate panels that will be created with ExtJS). The thing is that when for example I execute a manual process to create a new view (which is an Ext.panel), my jQuery code removes the DIV and creates it again in order to generate again this view. For some special modules the App needs to load an store with values that were inserted before in a database in cases where a new record is created, updated or deleted. The situation is that if a store was loaded one time, a model instance is created without any problem, but when I decide to generate again the same View, the store does not need to load again (since it was loaded before after the execution of a CRUD process), so I manage to control this scenario implementing some validations. However for some reason if this store is not loaded, another model instance is generated for some reason, so when I need to insert another record (using store.add), the instruction invokes the server's insert code (created in PHP) more than once. This behavior will occur every time I block the store's loading. What will be a good recommendation to control this type of situation?

  2. Well, finally I was able to resolve by myself.

    I just needed to control how many calls my application needs to handle. I used the ExtJS's beforesync event:

    beforesync( Object options, Object eOpts )

    I implement a Singleton class defining a boolean variable which controls than only 1 call will be allowed in case a user wants to add, update or delete a record.

    Thanks anyway for your interest in helping me with this.

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,330
    Answers
    3541
    Vote Rating
    847
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    I'm not sure I followed what you need.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha User jaadolio's Avatar
    Join Date
    Nov 2010
    Posts
    18
    Answers
    1
    Vote Rating
    0
    jaadolio is on a distinguished road

      0  

    Default


    Hi,
    The thing to be resolved is that when I execute an instruction to generate a view (an Ext.panel), which was generated before and now is created again dynamically without reloading the page, I need to avoid the app to instantiate more than one Ext.model because this will affect any CRUD process that a user will try to do later.
    Like for example I have a model defined like this:

    Code:
    Ext.define("JRSPPRV.model.TipoContenido", {
                    extend: 'Ext.data.Model'
                    ,fields: [
                                   {name: 'id_cons_tipo_contenido', type: 'int'},
                                   {name: 'id_tipo_contenido',  type: 'string'},
                                   {name: 'det_tipo_contenido',   type: 'string'}
                    ]
    });
    Which is referenced by this store:

    Code:
    Ext.define('JRSPPRV.store.TiposContenidos', {
        extend: 'Ext.data.Store'
        ,model: 'JRSPPRV.model.TipoContenido'
        ,autoSync: true
        ,autoSave: true
        ,proxy: {
            type: 'ajax',
            api: {
                create  : 'data/catalogos/TiposContenidosInserta.php',
                read    : 'data/catalogos/TiposContenidosLectura.php',
                update  : 'data/catalogos/TiposContenidosActualiza.php',
                destroy : 'data/catalogos/TiposContenidosElimina.php'
            },
    …
    During the first loading of the view, if I insert a new record, the POST params array only has 1 instance of records:

    Code:
    elements: [
               {‘id_cons_tipo_contenido’: 1, ‘id_tipo_contenido’: ‘TP-1’, ‘det_tipo_contenido’: ‘example text’}
    ]
    But when I destroy the Panel, remove the DIV an generate again the same view, If I try to do another insertion, the POST params array sent to the server is referencing 2 instances of records:

    Code:
    elements: [
    {‘id_cons_tipo_contenido’: 1, ‘id_tipo_contenido’: ‘TP-1’, ‘det_tipo_contenido’: ‘example text’},        {‘id_cons_tipo_contenido’: 2, ‘id_tipo_contenido’: ‘TP-1’, ‘det_tipo_contenido’: ‘example text’}
    ]
    And the instances will continue to appearing depending on how many generations I execute for the same panel. Probably one record instance will be accepted to be inserted but after that the PHP script will generated an error due to this behavior.

    So in conclusion, this is the problem that I’m experiencing right now. Any recommendation or suggestion about this will be appreciated.

  5. #4
    Sencha User jaadolio's Avatar
    Join Date
    Nov 2010
    Posts
    18
    Answers
    1
    Vote Rating
    0
    jaadolio is on a distinguished road

      0  

    Default


    Well, finally I was able to resolve by myself.

    I just needed to control how many calls my application needs to handle. I used the ExtJS's beforesync event:

    beforesync( Object options, Object eOpts )

    I implement a Singleton class defining a boolean variable which controls than only 1 call will be allowed in case a user wants to add, update or delete a record.

    Thanks anyway for your interest in helping me with this.