Results 1 to 3 of 3

Thread: Button + Ext.List + Ext.navigation.View + Panel = I need some help

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Jan 2013
    Location
    AccountKiller
    Posts
    9
    Vote Rating
    0
      0  

    Default Answered: Button + Ext.List + Ext.navigation.View + Panel = I need some help

    Hello!

    Kategori.png

    First, I have a button with an ID that is linked to a view that lists the data from JSON (see code below):

    Code:
    Ext.define('LG.view.categories', {
        extend: 'Ext.List',
        xtype: 'categories',
    
    
        requires: [
            'Ext.dataview.List',
            'Ext.data.proxy.JsonP',
            'Ext.data.Store'
        ],
        
        config: {
            title: 'Kategorier',
            cls: 'categories',
            indexBar: true,
            itemTpl: '<h2 class="YrkesBenamning">{YrkesBenamning}</h2>',
            onItemDisclosure: true,
            
            store: {
                autoLoad: true,
                fields: ['YrkesId', 'YrkesBenamning', 'antal'],
                
                grouper: {
                    groupFn: function(record) {
                        return record.get('YrkesBenamning')[0];
                    }
                },
    
    
                proxy: {
                    type: 'jsonp',
                    url: 'http://api.xxx.se/API.mvc/GetLillaGulaYrken?apikey=XXX',
                    reader: {
                        type: 'json',
                        rootProperty: 'responseData.feed.entries'
                    }
                }
            }
        }
    });
    Kategorilista.png

    When you click on an item to activate the function in my controller, see code below:

    Code:
        showCompany: function(list, index, element, record) {
            var YrkesId = record.get('YrkesId');
            console.log('id:' + YrkesId);
    /*
    *
    * Here I want to send the ID number to the next view, how do I do that?
    *
    */
    
            var companylistView = new Ext.create('LG.view.companylist');
            companylistView.setRecord(YrkesId);
            Ext.Viewport.setActiveItem(companylistView);
        }
    KategoriVald.png

    In this function I create also a new view called 'companlistView' and contains the following code below. Right now I manually added an ID number (10) for the JSON stream, such as: http://api.xxx.se/API.mvc/GetLillaGulaKunderByYrkeId/10?apikey=xxx
    But I need to get the ID number automatically for each item when you select a category, how do I do that? Do you understand what I mean?

    Code:
    Ext.define('LG.view.companylist', {
        extend: 'Ext.navigation.View',
        xtype: 'companylist',
        id: 'companyList',
    
    
        requires: [
            'Ext.dataview.List',
            'Ext.data.proxy.JsonP',
            'Ext.data.Store'
        ],
        
        config: {
            title: 'Skresultat',
            cls: 'companylist',
    
    
            items: {
                xtype: 'list',
                //itemTpl: '<h2 class="KNamn">{KNamn}</h2><p class="KAdress"><a href="http://maps.apple.com/?q={KAdress}, {KPostNr} {KOrt}">{KAdress}<br>{KPostNr} {KOrt}</a></p>',
                itemTpl: '<h2 class="KNamn">{KNamn}</h2>',
                onItemDisclosure: true,
                title: 'S&ouml;kresultat',
                cls: 'categorylist',
                
                store: {
                    autoLoad: true,
                    fields: ['PhoneNumber', 'KNamn', 'KId', 'KAdress', 'KOrt', 'KPostNr'],
    
    
                    proxy: {
                        type: 'jsonp',
                        url: 'http://api.xxx.se/API.mvc/GetLillaGulaKunderByYrkeId/10?apikey=xxx',
                        reader: {
                            type: 'json',
                            rootProperty: 'responseData.feed.entries'
                        }
                    }
                }
            }
        }
    });
    Foeretag.png

    The last view is printed by means of a push (). Code below:

    Code:
        showCompanyDetails: function(list, index, element, record) {
            this.getCompanylist().push({
                xtype: 'panel',
                title: record.get('KNamn'),
                html: '<p style="border:solid 1px red;"><a href="tel:' + record.get('PhoneNumber') + '">' + record.get('KNamn') + '<br>' + record.get('PhoneNumber') + '</a><p><p style="border:solid 1px green;"><a href="rmaps:ll=63.288303,18.70905">' + record.get('KAdress') + '<br>' + record.get('KPostNr') + ' ' + record.get('KOrt') + '</a><p>',
                scrollable: true,
                styleHtmlContent: true
            });
        }
    Please help me!

  2. First, instead of this:

    Code:
            var companylistView = new Ext.create('LG.view.companylist');
            companylistView.setRecord(YrkesId);
    I would do this:

    Code:
            var companylistView = Ext.create('LG.view.companylist', { //notice no new!
                record : record
            });
    Then in the LG.view.companylist component you have access to the record (will get the id in a second). This means that you can now take action on that using the updateRecord...

    Code:
    Ext.define('LG.view.companylist', {
        extend: 'Ext.navigation.View',
        xtype: 'companylist',
    
        requires: [
            'Ext.dataview.List',
            'Ext.data.proxy.JsonP',
            'Ext.data.Store'
        ],
        
        config: {
            title: 'Skresultat',
            cls: 'companylist',
    
            apiKey : 'xxxx',
    
            items: {
                xtype: 'list',
                //itemTpl: '<h2 class="KNamn">{KNamn}</h2><p class="KAdress"><a href="http://maps.apple.com/?q={KAdress}, {KPostNr} {KOrt}">{KAdress}<br>{KPostNr} {KOrt}</a></p>',
                itemTpl: '<h2 class="KNamn">{KNamn}</h2>',
                onItemDisclosure: true,
                title: 'S&ouml;kresultat',
                cls: 'categorylist',
                
                store: {
                    fields: ['PhoneNumber', 'KNamn', 'KId', 'KAdress', 'KOrt', 'KPostNr'],
                    proxy: {
                        type: 'jsonp',
                        reader: {
                            type: 'json',
                            rootProperty: 'responseData.feed.entries'
                        }
                    }
                }
            }
        },
    
        updateRecord : function(record) {
            var YrkesId = record.get('YrkesId'),
                list = this.down('list'),
                store = list.getStore(),
                proxy = store.getProxy() 
                apiKey = this.getApiKey();
    
            proxy.setUrl('http://api.xxx.se/API.mvc/GetLillaGulaKunderByYrkeId/' + YrkesId + '?apikey=' + apiKey);
    
            store.load();
        }
    });
    So the changes I made here is removed autoLoad from the store so we can handle loading, removed the url config from the proxy, added the updateRecord method to handle the record config or if you do a setRecord on this method. Now your store should load with the id in the URL. I also added a new config for apiKey to make it a little more elegant.

  3. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3932
    Vote Rating
    1272
      0  

    Default

    First, instead of this:

    Code:
            var companylistView = new Ext.create('LG.view.companylist');
            companylistView.setRecord(YrkesId);
    I would do this:

    Code:
            var companylistView = Ext.create('LG.view.companylist', { //notice no new!
                record : record
            });
    Then in the LG.view.companylist component you have access to the record (will get the id in a second). This means that you can now take action on that using the updateRecord...

    Code:
    Ext.define('LG.view.companylist', {
        extend: 'Ext.navigation.View',
        xtype: 'companylist',
    
        requires: [
            'Ext.dataview.List',
            'Ext.data.proxy.JsonP',
            'Ext.data.Store'
        ],
        
        config: {
            title: 'Skresultat',
            cls: 'companylist',
    
            apiKey : 'xxxx',
    
            items: {
                xtype: 'list',
                //itemTpl: '<h2 class="KNamn">{KNamn}</h2><p class="KAdress"><a href="http://maps.apple.com/?q={KAdress}, {KPostNr} {KOrt}">{KAdress}<br>{KPostNr} {KOrt}</a></p>',
                itemTpl: '<h2 class="KNamn">{KNamn}</h2>',
                onItemDisclosure: true,
                title: 'S&ouml;kresultat',
                cls: 'categorylist',
                
                store: {
                    fields: ['PhoneNumber', 'KNamn', 'KId', 'KAdress', 'KOrt', 'KPostNr'],
                    proxy: {
                        type: 'jsonp',
                        reader: {
                            type: 'json',
                            rootProperty: 'responseData.feed.entries'
                        }
                    }
                }
            }
        },
    
        updateRecord : function(record) {
            var YrkesId = record.get('YrkesId'),
                list = this.down('list'),
                store = list.getStore(),
                proxy = store.getProxy() 
                apiKey = this.getApiKey();
    
            proxy.setUrl('http://api.xxx.se/API.mvc/GetLillaGulaKunderByYrkeId/' + YrkesId + '?apikey=' + apiKey);
    
            store.load();
        }
    });
    So the changes I made here is removed autoLoad from the store so we can handle loading, removed the url config from the proxy, added the updateRecord method to handle the record config or if you do a setRecord on this method. Now your store should load with the id in the URL. I also added a new config for apiKey to make it a little more elegant.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    Jan 2013
    Location
    AccountKiller
    Posts
    9
    Vote Rating
    0
      0  

    Default

    Thank you so much, you saved my day!

Tags for this Thread

Posting Permissions

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