I want my view to grab the value of an attribute

 ̄綄美尐妖づ 提交于 2019-12-11 01:55:38

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/23742150/i-want-my-view-to-grab-the-value-of-an-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!