extjs - How to write structured data with JSON writer? -


how can include hasone associated model data in json post?

structured data required web api in form of:

{     id: 1234,     name: 'aaron smith',     address: {         address1: '1925 isaac newton sq',         address2: 'suite 300',         city: 'reston',         state: 'va',         zip: 20190     } } 

@nonino

i think know how having similar problem. can't associations give me associated data. anyway have scrounged on internet make custom writer or in default writers getrecorddata: function(record,operation)

here custom writer

ext.define('wakanda.writer', {      extend: 'ext.data.writer.json',     // alternateclassname: 'simplyfundraising.data.wakandawriter',      alias: 'writer.wakanda',      writeallfields: false,      getrecorddata: function(record,operation) {         debugger;         ext.apply(record.data,record.getassociateddata());         debugger;         var isphantom = record.phantom === true,             writeall = this.writeallfields || isphantom,             nameproperty = this.nameproperty,             fields = record.fields,             data = {},             changes,             name,             field,             key;          if (writeall) {             // console.log("getrecorddata1", this, arguments);             fields.each(function(field){                 if (field.persist) {                     debugger;                     name = field[nameproperty] || field.name;                     data[name] = record.get(field.name);                 } else {                  }              });         } else {             changes = record.getchanges();             debugger;             // console.log("getrecorddata2", this, arguments, changes);             (key in changes) {                 if (changes.hasownproperty(key)) {                     field = fields.get(key);                     name = field[nameproperty] || field.name;                     data[name] = changes[key];                 }             }             if (!isphantom) {                 debugger;                  data[record.idproperty] = record.getid();                 if(operation.action !== 'destroy'){                 data[record.stampproperty] = record.get(record.stampproperty);                 }             }         }         return {'__entities': [data]};     }  }); 

the key think in getrecorddata have statement ext.apply(record.data,record.getassociateddata()); if record.getassociateddata indeed return data ext.apply statement merge current record.data record.getassociateddata 1 json file. @ least hope happens. can't test until associations setup correctly.

hope helps, dan

  getrecorddata: function(record,operation) {         debugger;         ext.apply(record.data,record.getassociateddata());         debugger; 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -