1. #11
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    4
    Vote Rating
    0
    manpreet.singh is on a distinguished road

      0  

    Default It works with Json writer and not with Xml

    It works with Json writer and not with Xml


    Thanks Blee. It worked with writer.Json. But it didn't work with writer.Xml. I have gone ahead with changing my server to accept JSON instead of XML. I would request Sencha developers to make it working for writer.Xml as well.

  2. #12
    Sencha User
    Join Date
    Apr 2012
    Posts
    7
    Vote Rating
    2
    beachdog is on a distinguished road

      2  

    Default Or, in 4.1 use an override

    Or, in 4.1 use an override


    In 4.1 I achieved the same affect using an override
    Code:
    Ext.define('custom.JsonWriterOverride', {
        override: 'Ext.data.writer.Json',
    
        getRecordData: function(record) {
                Ext.apply(record.data,record.getAssociatedData());
                return record.data;
        }
    });
    usage then is then simply the normal:

    Code:
    Ext.define('My.model.Query', {
       extend: 'Ext.data.Model',
    
        requires: ['custom.JsonWriterOverride'],
     ...
      proxy: {
            type: 'rest',
            url: 'webApp/query.do',
            reader: {
                type: 'json',
                root: 'data'
            },
            writer: {
                type: 'json',
                writeAllFields: true
            }
        }
     });

  3. #13
    Sencha User
    Join Date
    Aug 2012
    Posts
    11
    Vote Rating
    0
    kivras is on a distinguished road

      0  

    Default


    Let me add something missing to pk69's solution that worked for me.

    Although the nested store is inside the parent store calling the Definition.fieldDefinitions(); function.
    This data is not stored inside the "Definition.fieldDefinitions" field.
    So if you manually set the data for example

    Code:
    Definitions.set("fieldDefinitions",[{some raw data},{more raw data}]);
    When calling the store.save() mehtod the writer will also send the nested data

  4. #14
    Sencha Premium Member
    Join Date
    Nov 2012
    Location
    Bangalore
    Posts
    79
    Vote Rating
    1
    rupamkhaitan is on a distinguished road

      0  

    Default


    Hi blee

    will your custom writer work with rest proxy as well?
    has anyone tried the above solution with rest api

  5. #15
    Sencha Premium Member
    Join Date
    Nov 2012
    Location
    Bangalore
    Posts
    79
    Vote Rating
    1
    rupamkhaitan is on a distinguished road

      0  

    Default


    i dint see the post of beachdog

    Hi beachdog,

    Can you paste some detailed code as how you are sending nested JSON data back to server using rest proxy api?

  6. #16
    Sencha User
    Join Date
    Aug 2008
    Posts
    3
    Vote Rating
    0
    hball is on a distinguished road

      0  

    Default


    your solution is quite pretty good for me .thanks!

  7. #17
    Sencha User
    Join Date
    Oct 2013
    Posts
    1
    Vote Rating
    0
    karasu-kun is on a distinguished road

      0  

    Default


    Quote Originally Posted by beachdog View Post
    In 4.1 I achieved the same affect using an override
    Code:
    Ext.define('custom.JsonWriterOverride', {
        override: 'Ext.data.writer.Json',
    
        getRecordData: function(record) {
                Ext.apply(record.data,record.getAssociatedData());
                return record.data;
        }
    });
    usage then is then simply the normal:

    Code:
    Ext.define('My.model.Query', {
       extend: 'Ext.data.Model',
    
        requires: ['custom.JsonWriterOverride'],
     ...
      proxy: {
            type: 'rest',
            url: 'webApp/query.do',
            reader: {
                type: 'json',
                root: 'data'
            },
            writer: {
                type: 'json',
                writeAllFields: true
            }
        }
     });
    this solution didn't work when some fields cannot be send in request (writeAllFields: false config for writer). my solution in this case:
    Code:
     // overriding Writer.getRecordData
     getRecordData: function(record, operation) {
        // call superclass method
        var data = this.superclass.getRecordData.apply(this, arguments);
        //data = this.callParent(arguments);
    
        // todo writeAllFields: true
        var associations = record.associations;
        var name, associationKey, associationData;
    
        // pass each association store and add all records from this store to record data
        associations.each(function(item){
            if(item.type == 'hasMany' && !Ext.isEmpty(item.name)){
                name = item.name;
                associationKey = item.associationKey;
                associationData = [];
                var store = record[name]();
                var writer = store.getProxy().getWriter();
                store.each(function(item){
                    associationData.push(writer.getRecordData(item));
                })
    
                if(!Ext.isEmpty(associationKey) && !Ext.isEmpty(associationData)){
                    data[associationKey] = associationData;
                }
            }
        });
    
        return data;
    }
    now this code ignore configuration optionwriteAllFields for nested objects but it's not difficult to fix it

Similar Threads

  1. Loading tree data from local "nested store"
    By mmix in forum Ext 3.x: Help & Discussion
    Replies: 12
    Last Post: 24 Aug 2010, 1:39 PM
  2. Replies: 1
    Last Post: 13 Nov 2009, 12:22 PM
  3. Replies: 2
    Last Post: 7 Jan 2009, 7:21 AM
  4. Form Layout + Nested Tab Panel + Nested BorderLayout
    By pluesch0r in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 5 Feb 2008, 8:25 AM
  5. saving a nested tree
    By notjoshing in forum Ext 1.x: Help & Discussion
    Replies: 5
    Last Post: 16 Aug 2007, 5:36 AM

Thread Participants: 14

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi