我想让我的视图来获取一个属性的值 [英] I want my view to grab the value of an attribute
本文介绍了我想让我的视图来获取一个属性的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要在docController中执行此操作,将被调用为
var docTemplateID = this.get('docTemplateID');
或/和
var model = this.get('model');
但是当我在docView中做同样的事情时,它不会获取当前文档的docTemplateID。
以下是查看中使用的功能
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');
}
}
});
路由和控制器是标准的,所以我没有链接它们,但是让我知道是否应该。
解决方案
控制器作为属性添加到您的视图中,您可以使用链接来抓取它们。
this.get('controller.docTemplateID');
http://emberjs.jsbin.com/giriyebi/1/edit
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.
解决方案
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
这篇关于我想让我的视图来获取一个属性的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文