Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why model is not accessible inside controller while accessible in handlebar template?

I have a model of patient object

 App.Router.map (function () {
    this.resource('patients');
    this.resource('patient', {path: ':patient_id'}, function(){
         this.resource('dashboard', function() {
             this.route('summary');

         });

    });
});




   App.PatientRoute = Ember.Route.extend({
          model: function(params) {
            return App.Patient.find(params.patient_id);
          },
          setupController: function(){
              console.log("Menu Items:" + App.PatientMenuItem.find() );
              this.controllerFor('patient').set('menuItems', App.PatientMenuItem.find());

          }
        });


App.DashboardSummaryRoute = Ember.Route.extend({
    setupController: function(){

        this.controllerFor('dashboard.summary').set('content', this.controllerFor('patient').get('model'));

        this.controllerFor('dashboard.summary').getPatient();
    }

});


App.DashboardSummaryController = Ember.ObjectController.extend({

  getPatient:function(){
      console.log(this.content.get_allergies);
  }
});

App.PatientController = Ember.ObjectController.extend({
    menuItems:[],    

});


<script type="text/x-handlebars" data-template-name="dashboard/summary">
Summary{{this.content.get_allergies}}
</script>

In the above I am not able to access the same get_allergies in DashboardSummaryController but I am able to access it in handlebars, Can anyone help me what is the mistake ?

Thanks in advance

like image 956
Swapnil Avatar asked Nov 23 '25 02:11

Swapnil


1 Answers

I don't know if this alone solves the problem, but always use the get() and set() methods when accessing properties. So i would suggest to try this in your getPatient() method:

App.DashboardSummaryController = Ember.ObjectController.extend({

  getPatient:function(){
      console.log(this.get("content.get_allergies"));
  }
});

Why does the template work? The Handlebars expression you have there is automatically translated into the call, i have suggested for your controller method.

like image 188
mavilein Avatar answered Nov 24 '25 22:11

mavilein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!