Jump to content

Understanding Views better...


pconkie

Recommended Posts

Looking for best practice advice.

If i create a new application and create some additional object and array variables like this:

Com.Frog.Utils.require(
    '//package/applications/C0295B45200484DAA47C7F2BECF1800B961701CC47C32B14/assets/styles/main.css',
    '//package/applications/C0295B45200484DAA47C7F2BECF1800B961701CC47C32B14/assets/views/record.ejs',
    '//package/applications/C0295B45200484DAA47C7F2BECF1800B961701CC47C32B14/assets/views/main.ejs'
).then(function() {
    Com.Frog.Controllers.Application.extend('C0295B45200484DAA47C7F2BECF1800B961701CC47C32B14.Controllers.Core', {
        defaults: {}
    }, {
        packageID: 'C0295B45200484DAA47C7F2BECF1800B961701CC47C32B14',
        user_data: {},
        sanction_data: {},
        sorted_data: [],
        search_data: {subject:'all',year:'all',house:'all',reg:'all'},
        acyear: {},
        xhr: {readyState: 4},
      init: function() { },
      
      etc..

Why can i only access some of them from a view when calling this.app?

Capture.PNG.1eb253deaa1e4c22aae8e982353895b8.PNG

How come user_data, sanction_data and sorted_data made it, but xhr, acyear and search_data didn't?

How reliable is it that (say for example) my user_data object is available from the view by calling this.app.user_data? Or do I really need to supply it to the view explicitly when loading the view from production.js?

 To summarise, I seem to have two choices to access the user_data object from the view::

this.element.find(".info").append(
  this.view('record.ejs', {
    user_data:user_data
  })
);

////in the view use/////////
<% user_data %>

or

this.element.find(".info-panel").append(
  this.view('record.ejs');
);

/////in the view use/////
<% this.app.user_data %>

Is one more efficient?  Why can't i take the second approach with e.g. search_data?

I take it that it is better to work with views? As opposed to doing everything in the production.js file?  

Thanks

Paul

Link to comment
Share on other sites

Your first example is the correct one - you pass the data you want to use into the view when you use it:

this.element.find(".info").append(
  this.view('record.ejs', {
    user_data:user_data
  })
);

////in the view use/////////
<% user_data %>

As for why this,app doesn't have all the data, I'm afraid I don't know! It's possibly to do with how the libraries we use optimise things, but that's a bit of a guess. One of our front end guru's in the office would probably know! However, internally we always pass the data into the view when we call it as in your example above, and so I would say that's best practice.

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...