User24231
User24231

Reputation: 506

Sencha Touch 2: Passing data from controller to a view

I am attempting to load a detail view for an item disclosure from a list but without using NavigationView and the "push()" command.

CONTROLLER:

Ext.define('App.controller.MyPlans', {
    extend: 'Ext.app.Controller',
    requires: ['App.view.EventDetail',
        'App.view.PlansContainer'],

    config: {
        refs: {

        },
        control: {
            'MyPlansList': {
                disclose: 'onDisclose'
            }
        }
    },

    onDisclose: function (view, record) {
        console.log("My Plans list disclosure " + record.get('id'));
        var eventDetailView = Ext.create('App.view.EventDetail');
        eventDetailView.setRecord(record);
        Ext.Viewport.setActiveItem(eventDetailView);
    }
});

VIEW:

Ext.define('App.view.EventDetail', {
    extend: 'Ext.Panel',
    xtype: 'EventDetail',

    config: {

        items: [{
            xtype: 'toolbar',
            docked: 'top',
            title: 'Event Name',
            items: [{
                xtype: 'button',
                id: 'addRunBackBtn',
                ui: 'back',
                text: 'Back'
            }]
        }, {
            xtype: 'panel',
            styleHtmlContent: true,
            itemTpl: [
                '<h1>{name}</h1>',
                '<h2>{location}</h2>',
                '<h2>{date}</h2>']
        }],

    }
});

I am basically trying to pass the data to the view using the "setRecord()" command but nothing seems to be loading in the view. Any thoughts??

Thanks

Upvotes: 3

Views: 4690

Answers (3)

Urmil Setia
Urmil Setia

Reputation: 159

I found the issue here:

A panel doesn't have a itemTpl

{
    xtype: 'panel',
    styleHtmlContent: true,
    itemTpl : [
        '<h1>{name}</h1>',
        '<h2>{location}</h2>',
        '<h2>{date}</h2>'
    ]
}

The one of the possible way to do it could be:

Change the VIEW:

{
    xtype: 'panel',
    id: 'thePanel',
    styleHtmlContent: true
}

Change the Controller:

onDisclose: function(me, record, target, index, e, eOpts) {
  ... 
  Ext.getCmp('thePanel').setHtml('<h1>'+record.get('name')+'</h1><h2>'+record.get('location')+'</h2><h2>'+record.get('date')'</h2>'); //For setting the Data
  ...
}

Hope this could help!

Upvotes: 0

Neo-coder
Neo-coder

Reputation: 7840

Instead of panel try list as below

Ext.define('App.view.EventDetail', {
    extend: 'Ext.TabPanel',
    xtype: 'EventDetail',
    config: {
        items: [{
            xtype: 'toolbar',
            docked: 'top',
            title: 'Event Name',
            items: [{
                xtype: 'button',
                id: 'addRunBackBtn',
                ui: 'back',
                text: 'Back'
            }]
        }, {
            xtype: 'list',
            styleHtmlContent: true,
            itemTpl: [
                '<h1>{name}</h1>',
                '<h2>{location}</h2>',
                '<h2>{date}</h2>']
        }],
    }
});

Upvotes: 0

tiger
tiger

Reputation: 26

Instead of ItemTpl just write Tpl. I doubt that itemTpl exists without list xtype.

Other thing is put Tpl inside config:

{tpl:['<div class="ListItemContent">{descriptionddata}</div>']}

The answer before/above me is good but if you intend of keeping your formatting inside view and not in controller then , it works by using setData instead of setRecord

detailview.setData({title:record.get('title'), description:record.get('descriptiondata')});

Upvotes: 1

Related Questions