Ian Steffy
Ian Steffy

Reputation: 1234

I want my view to grab the value of an attribute

My view is not grabbing the value of an attribute I set for the model.

To do this in the docController would be called like

var docTemplateID = this.get('docTemplateID'); 

or/and

var model = this.get('model');

but when I do the same thing in the docView, it does not grab the value of the current doc's docTemplateID.

Here is the function used in the View

VpcYeoman.DocView = Ember.View.extend({ 
    toggleLetterSwitch: false,
    togglePermitSwitch: false,  
  templateName: 'doc',
  willInsertElement: function() {
      var model = this.get('model');
      var docTemplateID = this.get('docTemplateID');
      if ( docTemplateID == 2) {
        this.set('toggleLetterSwitch', true);
        this.set('togglePermitSwitch', false);
        console.log('docTemplateID equals 2');
      } else {
        this.set('toggleLetterSwitch', false);
        this.set('togglePermitSwitch', true);
        console.log(this.get('toggleLetterSwitch'));
        console.log('docTemplateID else 1');
      }
  }
});

The routes and controllers are standard so I didn't link them, but let me know if should.

Upvotes: 2

Views: 51

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

The controller is added as a property on your view, and you can grab them using chaining.

this.get('controller.docTemplateID');

http://emberjs.jsbin.com/giriyebi/1/edit

Upvotes: 1

Related Questions