開発環境または実稼働環境に基づいてユーザー インターフェイス機能を有効/無効にする構成 JavaScript ファイルを実装しようとすると、いくつかの奇妙な動作に気付きました。いくつかの説明を使用できます。
これはフラットなアプリケーションで、javascript を index.js、dashboard.js、taxonomy.js の 3 つのファイルに分割しました。
<script type = "text/javascript" src = "/static/js/taxonomy.js"></script>
<script type = "text/javascript" src = "/static/js/dashboard.js"></script>
<script type = "text/javascript" src = "/static/js/index.js"></script>
<script type = "text/javascript" src = "/static/js/config.js"></script>
インデックス スクリプトは、ログイン、ログアウト、および要素の初期化機能を処理します。そのように定義されています
$(document).ready(function(){
$.ajax({
//query db for login
success : function(){
loginHandler()
}
});
function loginHandler(){
initializeDashboardElements()
initializeTaxonomyElements()
}
taxonomy.js 内には定義はありませんが、指定された HTML 要素に jQuery UI バインディングを適用する$(document).ready()
定義が存在します。initializeTaxonomyElements()
そのような要素の 1 つは、現在 4 つのタブを含むタブ ウィジェットですが、さらに大きくなると予想されます。
内部config.js
には、本番環境用に次のものがあります。
$(document).ready(function(){
$("#tabs").tabs("option", "disabled", [1, 2]);
});
このセットアップを考えると、エラーが発生します
Error: cannot call methods on tabs prior to initialization; attempted to call method 'option'
また、宣言initializeTaxonomyElements()
内でこれを試しました。$(document).ready()
同じエラーが発生します。
この問題を解決するための提案はありますか?