Sencha Touch 2 Ext.List - programmatically add detail view

5.5k views Asked by At

I’m trying to add different detail view based on taped item in list.

  • I have home screen that is using List component and this view is displaying ['Real estate', 'Vehicles', 'Jobs']... as menu items.
  • Based on selected item in list, I want to display different view.
    • And I want to follow MVC design pattern..

Here is some code... App.js

Ext.application({
name: 'App',

controllers: ['Main'],
views: ['Viewport', 'HomePage'],
stores: ['HomePageItems'],
models: ['HomePageItem'],

launch: function () {
    Ext.Viewport.add(Ext.create('App.view.Viewport'));
}

});

Viewport.js

Ext.define("App.view.Viewport", {
extend: 'Ext.navigation.View',

requires: [ 'App.view.realestate.Realestate',
            'App.view.HomePage',
            'App.view.jobs.Jobs',
            'App.view.other.Other',
            'App.view.vehicles.Vehicles'
           ],

config: {
    items: [
        {
            xtype: 'homepage'
        }
    ]
}

});

HomePage.js ( xtype = "homepage" )

Ext.define('App.view.HomePage', {
extend: 'Ext.List',
xtype: 'homepage',
id: 'homepage',

config: {
    title: 'Oglasi',
    itemTpl: '<strong>{name}</strong><p style="color:gray; font-size:8pt">{description}</p>',
    store: 'HomePageItems',
    onItemDisclosure: true
}

});

Main.js

Ext.define('App.controller.Main', {
extend: 'Ext.app.Controller',

config: {
    refs: {
        main: '#homepage'
    },

    control: {
        'homepage': {
            disclose: 'HookUpDetailView'
        }
    }
},

HookUpDetailView: function (element, record, target, index, ev) {
    // TO DO: I have 4 differente views to load programmaticaly based on selected item in List
    //'App.view.realestate.Realestate'
    //'App.view.jobs.Jobs'
    //'App.view.other.Other'
    //'App.view.vehicles.Vehicles'
}

});

I found one example, but it's not working for me (push method doesn't exist)

this.getMain().push({
        xtype: 'realestatehome'
    });

Thank in advance!

3

There are 3 answers

0
fuzzyLikeSheep On

Push should work. You could try something like this.

  HookUpDetailView: function (list, record) {

           if(record.data.description==='real estate'){

                  this.getRealEstate().push({
                      xtype: 'realestatehome',
                      title: record.data.description,
                      data.  record.data

           });

           if(record.data.description==='Vehicles'){

                  this.getVehicles().push({
                      xtype: 'vehicles',
                      title: record.data.description,
                      data.  record.data

           });


     }
}

And a particular view could look like

Ext.define('App.view.RealEstateHome', {
    extend: 'Ext.Panel',
    xtype: 'realestatehome',
    config: {
        styleHtmlContent: true,
        scrollable: 'vertical',
        tpl: [
            '{description}, {example}, {example}, {example}'
        ]
    }
});

And the refs to access your particular view should look something like

refs: {
        realEstate: 'realestatehome',
        vehicles:   'vehicleshome'
    },

Hope that helps

1
Ruan Mendes On

The method you're looking for is

http://docs.sencha.com/touch/2-0/#!/api/Ext.Container-method-add

this.getMain().add({xtype: 'realestatehome'});

But what you have doesnt make sense, realestatehome is a list, you can't add a component under it. You need to read about layoutsFrom the link above

0
Aleksandar Borkovac On

I made a mistake in controller this.getMain() get main is returning Ext.List and I need Ext.navigation.View that have 'push' method.

So... I added xtype and id to my viewport ("container") and quick change in my controller solved my troubles...

refs: {
    main: '#homepage',
    container: '#container'
}

and instead of getting Ext.List object

this.getContainer().push({
    xtype: 'realestatehome'
});

And this work like a charm :)