我的 View 没有获取我为模型设置的属性值。
在 docController 中执行此操作将被称为
var docTemplateID = this.get('docTemplateID');
或/和
var model = this.get('model');
但是当我在 docView 中做同样的事情时,它不会获取当前文档的 docTemplateID 的值。
这是 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');
}
}
});
路由和 Controller 是标准的,所以我没有链接它们,但如果应该的话请告诉我。
最佳答案
Controller 作为属性添加到您的 View 中,您可以使用链接来获取它们。
this.get('controller.docTemplateID');
关于javascript - 我希望我的 View 获取属性的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23742150/