extjs - Connect two models by ID -


i asked extjs question few days ago, , side note asked how connect 2 models. main answer got answered, still couldn't figure out other problem, opening new question it.

it might silly problem again, here is:

i json server, looks this:

{ "success": true, "result": {     "publishers": [         {           "id": "009999",           "type": "abc",           "isreceipient": false,           "description": "xyz"         },         {           "id": 45,           "type": "abc",           "isreceipient": true,           "description": "xyz"         },         {           "id": 45,           "type": "abc",           "isreceipient": false,           "description": ""         }         ],         "notes": [         {           "publisherid": "009999",           "text": "asdasd",           "created": "2014-02-23t18:24:06.074z"         },         {           "publisherid": "46",           "text": "asdasd",           "created": "2014-02-23t18:24:06.074z"         },         {           "publisherid": 45,           "text": "asdasd",           "created": "2014-02-23t18:24:06.074z"         }     ] } } 

so 2 arrays, publishers , notes. have 2 model that, load them in models controller using loadrawdata(), works, got publishers , notes in store. (they both have store - publishers , notes). need use publisherid in notes display publishers description. tried lot of things find using google , sancha docs: associations, hasmany, hasone, belongsto , creating third store consisting of 2 aggregated model. nothing worked far.

what want have store has every notes, plus notes have publisher info.

i'll copy 2 models below, can see there, commented out have been trying. tried changing id's, names etc., variations of these. never notes have publisher's info.

ext.define('ma.model.note', {     extend: 'ext.data.model',     fields: [         'publisherid',         'text' ,         //hasone publisher         {             name: 'created',             type: 'date',             dateformat: 'c'//'d-m-y h:i:s' //"2014-02-23t18:24:06.074z" needed: "02/23 18:24"         }     ]     // hasone: [     //     {     //         name: 'publisher',     //         model: 'publisher',     //         associationkey: 'publisherid'     //     }     // ],      // associations: [     //     {     //         type: 'hasone',     //         model: 'publisher',     //         primarykey: 'id',     //         foreignkey: 'publisherid'     //     }     // ]      // associations : [     //     {     //         type           : 'hasone',     //         model          : 'ma.model.publisher',     //         gettername     : 'getpublisher',     //         associatedname : 'user',     //         associationkey : 'user'     //     },     //     {     //         type           : 'belongsto',     //         model          : 'ma.model.publisher',     //         gettername     : 'getpublisher',     //         associatedname : 'publisher',     //         associationkey : 'publisherid'     //     }     // ]      // belongsto: [     //     {     //         model: 'ma.model.publisher',     //         name: 'note',     //         primarykey: 'publisherid',     //         foreignkey: 'id',     //         // foreignstore: 'publishers'     //     }     // ] }); 

publisher:

ext.define('ma.model.publisher', {     extend: 'ext.data.model',      idproperty: 'id',     fields: [         'id',         'type' ,         {             name:'isreceipient',             type:'boolean'         },         'description'     ]     // hasmany:  [     //     {     //         model: 'ma.model.note',     //         name: 'note',     //         primarykey: 'id',     //         foreignkey: 'publisherid',     //         // foreignstore: 'notes'     //     }     // ], }); 

am on right track? should use associations? couldn't difference between associations , hasman/one/belongto properties, guess there isn't really, way declare it.

edit: idea have dataview class, has store holds notes , corresponding publisher notes. have main panel:

    items: [         {             xtype: 'create-note-panel',             flex: 1         },         {             xtype: 'notes-panel',             store: 'notes',             flex: 1         }     ] 

and notes-panel looks this:

ext.define('ma.view.sections.notes.notespanel' ,{     extend: 'ext.dataview',     alias: 'widget.notes-panel',     // deferinitialrefresh: true,      itemselector: 'div.notes-list',     tpl:  new ext.xtemplate(         '<div class="notes-list">',             '<tpl for=".">',                 '<p>{created}, {publisherid}</p>',                 '<p>{text}</p>',                 '<hr />',             '</tpl>',         '</div>'     ),      emptytext: 'no data available',     initcomponent: function() {         var me = this,             publisherstore = ext.data.storemanager.lookup('publishers');         //me.addevents(   //just messing here, trying stuff         //    'user-offer-activities'         //);         me.callparent(arguments);     }     //renderto: ext.getbody()  }) ; 

notice publisherid in template. need publisher description there. didn't want use grid, dataview seemed pretty solution, thought joining 2 stores easy, couldn't figure out yet :(

i have created fiddle results in after (displaying data both models in view).

it bit of longwinded approach though, because of way tpl works don't have access model, data within it. created function on tpl gets record we're interested in model based on publisherid.

https://fiddle.sencha.com/#fiddle/o9o

note: created fiddle without using associations between models, create hasone association notes publisher foreignkey linking id , publisherid in respective models (though still don't think enable refer members directly in tpl).


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -