Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Nested loading / nested saving in new data package

  1. #11
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    4
    Vote Rating
    0
      0  

    Default 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
      2  

    Default 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
      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
      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
      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
      0  

    Default

    your solution is quite pretty good for me .thanks!

  7. #17
    Sencha User
    Join Date
    Oct 2013
    Posts
    1
    Vote Rating
    0
      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

Page 2 of 2 FirstFirst 12

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •