簡體   English   中英

在JS文件中使用帶有ember的If語句

[英]Using If statement with ember in a JS file

我不知道這是如何工作的,但我需要在下面的代碼中添加一個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。 有什么幫助嗎? 謝謝

在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..
  }
}

您可以使用計算屬性。 此外,如果您需要,可以將計算屬性與可能動態更改的其他屬性綁定。( 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(),

  .....

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM