Jump to content

Understanding Views better...

Recommended Posts

Looking for best practice advice.

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

).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() { },

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


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.view('record.ejs', {

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



/////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?  



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.view('record.ejs', {

////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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...