View Full Version : Best Practice: Populating view

16 Jan 2013, 2:29 PM

So what I'm trying to do is figure out the best way to pass in variables to a view. Is it from the controller? If so what is the best way to go about doing that?

Let's say I have a login screen where I want to display the application version and the some other custom device information. How would I go about passing that info into the view?

Ext.define('MyApp.view.Login', {
extend: 'Ext.form.Panel',
xtype: 'loginform',
config: {
items: [
{ xtype: 'label', cls: 'appVersion', html: 'Version #:' + versionNumber }

1.) How would I populate that information? Ideally I think the controller would be the best place.

2.) How much different would it be if I used tpl instead of html ?

Thanks for any help!

Update: I apologize if I posted this in the wrong place. I realized I am referring to Touch 2 and this is Ext 4.x. There's no option for moving the thread. Still would welcome any suggestions or advice.

17 Jan 2013, 6:47 AM
For me, it depends. If you're returning data from the server on each "refresh" of the view, I like just returning the HTML from the server...much easier to maintain than with views.

On the other hand, if your view is being populated from a store, that store has in-memory records, and each record can populate the view with the data it needs, then a TPL makes good sense since you don't have to make a round trip to the server just to generate HTML.

And yes, I'd do it from the controller, since that's where you're interacting with all the events that occur in your app.

17 Jan 2013, 7:08 AM
@existdissolve Thanks for your feedback. I guess my main concern is apart from the moment creation for the view, is there any other way to pass data / variables to the view from the controller?

For instance what if you built some complex dashboard. You have a controller with multiple views and some nested views. Let's say you are monitoring data from an external source or data that changes without user interaction.

How would I reflect those changes to my view?

With a model any update would trigger a "change" event. You can use the change event to update the view. With a controller monitoring some external data or something external that is not a user interaction, how to update the view to reflect this change?