pass data from controller to existing view in sencha tocuh

三世轮回 提交于 2019-12-08 14:23:25

You said your getting data in panel's initialize method, So you can do this

initialize: function(){
       this.callParent();
       console.log("initialized");
       var data = this.config.data;
       this.down('titlebar').setTitle(data.member_data);
}

Based on your comments, You can set data to the panel you setRecord.

Update

Have a reference to the formPanel in your controller

config : {
        refs : {
            Profileinfo: 'profileinfo'
        }
    } 

In ProfileInfo view

For selecting label i suggest you to give itemId to label like this

{ 
  xtype:'label',
   itemId: 'member'
}

In your controller loadList function

If you have fields (textfield, selectfield, etc) inside formpanel,you can use setValues() for setting data as i done below.

But label is not a field so, you have to select it and then use setHtml() to set data

loadList:function(me, index, target, record, e, eOpts){

 Ext.Viewport.setActiveItem({ xtype:'profileinfo'});

 this.getProfileinfo().setValues(record.getData());

 //As you posted in your question, I am assuming member label is child of Profileinfo
 this.getProfileinfo().getComponent('member').setHtml(record.getData().member_name)

}

Most important

Properties or fields in the record should match name of the fields in the frompanel, Then only setValues() works.

Example

If you have field like this in frompanel

 {
   xtype: 'textfield',
   label: 'First Name',
   name: 'Firstname'
 }

record.getData() should have Firstname property in it.


Update for setting data in panel with tpl

Lets say you have panel like this

Ext.define('MailApp.view.MessageDetails', {
    extend: 'Ext.Panel',
    xtype: 'messageDetails',   
    config: {
        items : [{
                 xtype: 'titlebar',
                 docked: 'top',
                 itemId: 'detailsTitle'
              },
            {
            xtype : 'panel',
            itemId : 'details',
            tpl : new Ext.Template(
            '<div class="details">',
            '<p>From : {from}</p>',
            '<p>Subject : {subject}</p>',
            '<p>Message : {message}</p>',                   
            </div>'
            )
        }]
    }
});

In your controller loadList function

loadList:function(me, index, target, record, e, eOpts){
 var data = record.getData();

 Ext.Viewport.setActiveItem({ xtype:'messageDetails'});

 // Don't forget to put refference to work this.getMessageDetails()

 this.getMessageDetails().getComponent('details').setData(data);

 this.getMessageDetails().getComponent('detailsTitle').setHtml(data.detailsTitle)

}

When you print console.log(record.data()) you should have

Object {from: "Apple", subject: "welcome", message: "Apple welcomes you to mail app", detailsTitle: " Mail Deatils", id: "ext-record-1", xindex: 1}

I mean properties should match fields in the tpl.

This is what you can do to set data in panel's custom HTML using tpl.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!