2016-04-26 4 views
0

私たちはextjs 3.2.1 JavaScriptフレームワークを使用しています。グリッドパネルの1つにアクションメニューがあります。データベースから取得した値に基づいて、メニューを表示または非表示にする必要があります。私はその目的のためにメニューの隠しプロパティを使用することができます。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()、:破壊のバグが3.2.1に存在しない限り、1.1.0

は、あなたのために働いされなければなりません。

+0

私が隠しtrueまたはfalseを設定すると機能します。問題は、非表示にするかどうかにかかわらず、データベースから値を取得する必要があることです。データベース呼び出しは非同期で実行され、メニューが初期化された後に戻ります。 –

+0

@MuthuAnnamalai 'hide()'関数を使用すると、コンポーネントが初期化された後にコンポーネントを隠すか表示することができます。 – Alexander

+0

初期化した後、データベースからthis.getMenuActions [0] .hidden =値にアクセスしようとしましたが、私のためには機能しませんでした。私は本当にどこで間違っているのか分かりません。 –