1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    82
    Vote Rating
    1
    Answers
    5
    markevans is on a distinguished road

      0  

    Default Answered: Displaying associated data in a list.

    Answered: Displaying associated data in a list.


    I've tried searching for an answer, as it is possible the guidance I need is relatively simple. I have a number of stores with associations (belongsTo, hasMany) and I'm trying to utilize data in a list from that list's store's associated data. Based on some of the results I found in searching, I've tried adding a "prepareData" function to the List which does seem to run as the list is rendered, but unclear how to get the associated data from within the prepareData function (assuming this is the right way to go.) Any help or tips would be greatly appreciated.

    List view:
    Code:
    Ext.define('Tally.view.Games', {	extend: 'Ext.List',
    	xtype: 'gamelist',
    	prepareData: function(data, idx, record)
    				{
    					data.hasRelated = "test";
                                            data.locname = data.location.name; // I know this isn't right, but how?
    					return data;
    				},
    	
    	requires: [
    		'Ext.dataview.List',
    		'Tally.store.Games'
    	],
    	
    	config: {
    		title: 'Games',
    		itemTpl: '{label}{hasRelated}',
    		store: 'Games'
    	}
    });
    Game Model:
    Code:
    Ext.define('Tally.model.Game', {
      extend: 'Ext.data.Model',
      
    	requires: [ 'Ext.data.identifier.Uuid',
    	 			'Ext.data.proxy.LocalStorage'],
    
    
    
    
      config: {
    	
    	identifier: 'uuid',
    	belongsTo: 'Team',
    	hasMany: 'Tevent',
    	belongsTo: 'Location',
    	hasMany: 'Series',
    	
        fields: [
        		{ name: 'id', type: 'string' },
    			{ name: 'label', type: 'string' },
    	       	{ name: 'name', type: 'string' },
    	        { name: 'team_id', type: 'string' },
    			{ name: 'location_id', type: 'string' },
    	        { name: 'starttime', type: 'date' },
    	        { name: 'closetime', type: 'date' },
    	        { name: 'notes', type: 'string' },
    	        { name: 'gamestatus', type: 'string' },
    	        { name: 'publicstatus', type: 'string' },
    			{ name: 'lastupdate', type: 'date' },
    			{ name: 'createddate', type: 'date' },
    			{ name: 'dirty', type: 'boolean' }
        		],
        
        proxy: {
          	type: 'localstorage',
    		id: 'games'
          }
        }
      
    });
    Location Model:
    Code:
    Ext.define('Tally.model.Location', {
      extend: 'Ext.data.Model',
      
    	requires: [ 'Ext.data.identifier.Uuid',
    	 			'Ext.data.proxy.LocalStorage'],
    
    
    
    
      config: {
    	
    	identifier: 'uuid',
    	hasMany: 'Game',
    	
        fields: [
        		{ name: 'id', type: 'string' },
    	        { name: 'name', type: 'string' },
    	        { name: 'phone', type: 'string' },
    	        { name: 'address1', type: 'string' },
    	        { name: 'address2', type: 'string' },
    	        { name: 'roomsuite', type: 'string' },
    	        { name: 'city', type: 'string' },
    	        { name: 'state', type: 'string' },
    	        { name: 'country', type: 'string' },
    	        { name: 'postalcode', type: 'string' },
    	        { name: 'latitude', type: 'float' },
    	        { name: 'longitude', type: 'float' },
    			{ name: 'lastupdate', type: 'date' },
    			{ name: 'createddate', type: 'date' },
    			{ name: 'dirty', type: 'boolean' }
        ],
        
        proxy: {
          	type: 'localstorage',
    		id: 'locations'
          }
        }
      
    });

  2. Ultimately, my issue here being unable to read associated data was connected to my lack of full path and filename in my "belongsTo" and "hasMany" model definitions. That is, be sure to add "Myapp.model.ModelName", not just "ModelName".

    Just putting this here in case anyone wanders across this with a similar problem.

    See http://www.sencha.com/forum/showthre...-being-created for more info.

  3. #2
    Sencha User
    Join Date
    Apr 2012
    Posts
    82
    Vote Rating
    1
    Answers
    5
    markevans is on a distinguished road

      0  

    Default Do I need something like this?

    Do I need something like this?


    Is anyone using this? I guess I thought the standard framework would provide for something like this once all of the associations were configured properly.

    http://appointsolutions.com/2012/07/...-and-ext-js-4/

  4. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    82
    Vote Rating
    1
    Answers
    5
    markevans is on a distinguished road

      0  

    Default Root problem = associations need full path+filename.

    Root problem = associations need full path+filename.


    Ultimately, my issue here being unable to read associated data was connected to my lack of full path and filename in my "belongsTo" and "hasMany" model definitions. That is, be sure to add "Myapp.model.ModelName", not just "ModelName".

    Just putting this here in case anyone wanders across this with a similar problem.

    See http://www.sencha.com/forum/showthre...-being-created for more info.