Thomas Vervik
Thomas Vervik

Reputation: 4535

How to give parameter to view and retrieve in the view

I saw some example with Ext (cant find it again now) that it should be possible to give parameter to the view like I do below in the push function. If this is also possible in Sencha 2, how can I retrive this value in the view ?

var saveResponse = account.save({
      success: function(model, operation) {
          console.log('The Account was created, response: '+model);
          loginview.push({
              xtype: 'adultmenulist',
              adult: model
          });
      },
      failure: function(model, operation) {
          ....
      }
});

Upvotes: 2

Views: 2036

Answers (2)

Titouan de Bailleul
Titouan de Bailleul

Reputation: 12949

In your any controller, you just need to create a reference to you view :

refs: {
    adultMenuList:'adultmenulist'
}

Then, wherever you want in the controller, you can do :

this.getAdultMenuList().getAdult();

For this to work your adultmenulist need to add an adult parameter defined in its config :

Ext.define('MyApp.view.AdultMenuList, {
  extend: 'Ext.Container',
  config: {
    ...
    adult:null
  }    
});

Hope this helped

Upvotes: 0

Rob
Rob

Reputation: 4947

I usually create a function in my custom object called something like: updateWithRecord. Whenever i push the object i call this method and then proceed to push it like this:

var record = Ext.create('MyApp.model.Adult', { firstName: 'Thomas', lastName: 'Vervik' });
this.getAdultMenuList().updateWithRecord(record);
this.getNav().push(this.getAdultMenuList());

Note how i use MVC ref's for both my detailpage and the NavigationView:

refs: {
    nav: {
        selector: 'mainnavigation',
        xtype: 'mainnavigation',
        autoCreate: true
    },
    adultMenuList: {
       selector: 'adultmenulist',
       xtype: 'adultmenulist',
       autoCreate: true
   }
}

And my page would look something like this:

Ext.define('MyApp.view.AdultMenuList, {
   extend: 'Ext.Container',
   config: {
     items: [
        { xtype: 'label', name: 'firstName' }, { xtype: 'label', name: 'lastName' }
      ]
    },
    updateWithRecord: function(record) {
       this.down('label[name="firstName"]').setHtml(record.get('firstName'));
       this.down('label[name="lastName"]').setHtml(record.get('lastName'));
    }    
});

Upvotes: 2

Related Questions