2016-04-26 119 views
0

我們使用的是extjs 3.2.1 JavaScript框架。在其中一個網格面板上有一個動作菜單。根據從數據庫中檢索的值,我需要顯示或隱藏菜單。爲此,我可以使用菜單的隱藏屬性。ExtJs處理異步調用

問題是我用來異步檢索數據庫運行值的函數,並且需要時間來檢索該值,並且在返回時菜單已經被初始化。這裏有兩種方法。

employeeProfile: function(profileType) { 
    CR.Controllers.Employee.GetProfile(function(result) { 
     if (CR.CRError.ParseResult(result)) { 
      switch (profileType) { 
       case "IsStandardAllowed": 
        return result.IsStandardAllowed === 1 ? true : false; 
       case "IsUploadAllowed": 
        return result.IsUploadAllowed === 1 ? true : false; 
       case "IsCopyAllowed": 
        return result.IsCopyAllowed === 1 ? true : false; 
       default: 
        return true; 
      } 
     } 
     return true; 
    }, this); 
}, 

getMenuActions: 
function() { 
    return [ 
     // add button 
     new CR.EmployeePanelAction({ 
      text: this.lang_newFromStandard, 
      tooltip: this.lang_tipNewFromStandard, 
      handler: this.onNewFromTemplate, 
      hidden: this.EmployeeProfile("IsStandardAllowed") 
      scope: this 
     }), 
     new CR.EmployeePanelAction({ 
      text: this.lang_newFromUpload, 
      tooltip: this.lang_tipNewFromUpload, 
      handler: this.onNewFromUpload, 
      hidden: this.employeeProfile("IsUploadAllowed"), 
      scope: this 
     }), 
     new CR.EmployeePanelAction({ 
      text: this.lang_newFromCopy, 
      tooltip: this.lang_tipNewFromCopy, 
      handler: this.onNewFromCopy, 
      hidden: this.employeeProfile("IsCopyAllowed"), 
      scope: this 
     }) 
    ]; 
}, 

回答

0

問題是我不明白JavaScript的回調和範圍。我將回調方法與範圍一起傳遞給數據庫檢索方法,並且工作正常。這裏是我用來成功檢索的方法。

isImageActionAllowed: function(setImageActions, scope) { 
     MVC.Controllers.Users.GetUserProfile(function(result) { 
      if(MVC.Error.ParseResult(result)) { 
       setImageActions.call(scope, result); 
      } 
     }, this); 
    }, 
0

Ext.Button.hide(),可自從:1.1.0

應該爲你工作,除非有一個3.2.1破錯誤。

+0

它的作品,如果我設置隱藏真或假。問題是我必須從數據庫中獲取價值,無論我是否需要隱藏。數據庫調用運行異步並在菜單初始化後返回 –

+0

@MuthuAnnamalai使用'hide()'函數,可以隱藏或顯示已初始化的組件,那麼問題出在哪裏? – Alexander

+0

初始化後,我試圖從數據庫訪問this.getMenuActions [0] .hidden = value,但沒有爲我工作。我真的不知道我在哪裏犯錯。 –