我不确定这是如何工作的,但我需要在下面的代码中添加一个if语句。 我知道Javascript但不是ember,我仍然在学习它 我的文件名为:CatalogueListController.js 以及代码:
App.CataloguelistController = Em.ArrayController.extend(Ember.PaginationSupport, {
needs: ["search", "accountBrowse"],
content: [],
total: 0,
isLoading: false,
outofcount: 0,
searchquery: '',
classid: 0,
attributelist: '',
processguid: '',
quotetypeMetaBinding: "App.metaDataController.QUOTETYPE",
addToBulk: function(context) {
var self = this,
accountguid = App.selectedAccountGuid,
quotetype = (context && context.metacode) ? context.metacode : App.currentQuotetype,
itemArray = [];
//some more code here
},
//i need to put the if here if it is for a certain accountguid then have
currentViewList: true,
currentViewBulk: false,
//else have this
currentViewList: false,
currentViewBulk: true,
mainPage: false,
andOr: [
{"name": "Match All", "value": "AND"},
{"name": "Match Any", "value": "OR"}
],
andOrSelected: 'AND',
我已将评论放在需要if的地方。 有什么帮助吗? 感谢
答案 0 :(得分:1)
在init上有条件地设置这些属性:
App.CataloguelistController = Em.ArrayController.extend(Ember.PaginationSupport, {
init: function(){
this._super();
if(//somecondition){
this.set('currentViewList', true);
this.set('currentViewBulk', false);
}else{
// set them to something else..
}
}
答案 1 :(得分:1)
您可以使用计算属性。此外,如果您需要,可以将计算属性与可能动态更改的其他属性绑定。(http://emberjs.com/guides/object-model/computed-properties/)
App.CataloguelistController = Em.ArrayController.extend(Ember.PaginationSupport, {
needs: ["search", "accountBrowse"],
.....
currentViewList:function(){
if(/*it is for a certain accountguid*/){
return true;
}else{
return false;
}
}.property(),
currentViewBulk:function(){
if(/*it is for a certain accountguid*/){
return true;
}else{
return false;
}
}.property(),
.....