2016-09-14 4 views
0

私は選択したドロップダウンを入力してドロップダウンするプラグイン(https://github.com/olivM/jQuery-Selectbox)を持っています。ファイアウブでは動作するがコード実行では動作しないコマンドを呼び出す方法は?

次の方法では、コード内の偶数ハンドラを介して、ドロップダウンで要素の変更を切り離すことはできません。

私はこれをFirebugのインスペクタで手動でのみ行うことができます。

$('#elem').selectbox('detach'); 
$('#elem').selectbox('attach'); 

デタッチして選択ボックスをhtmlドロップダウンに追加するにはどうすればよいですか?

Method  Description 
attach .selectbox("attach") Attach the select box to a jQuery selection. This will hide the element and create its custom replacement. 
change .selectbox("change") Change selected attribute of the selectbox. 
close .selectbox("close")  Close opened selectbox. 
detach .selectbox("detach") Remove the selectbox functionality completely. This will return the element back to its pre-init state. 
disable .selectbox("disable") Disable the selectbox. 
enable .selectbox("enable") Enable the selectbox. 
open .selectbox("open") Call up attached selectbox. 
option .selectbox("option", options) Get or set any selectbox option. If no value is specified, will act as a getter. 
+0

をので、私は、アーカイブをフェッチ://web.archive.org/web/20160323122843/http://www.bulgaria-web-developers.com/projects/javascript/selectbox/ – Vahe

+0

不思議なことに、私はコマンドを稼働させるためにタイムアウトを使う必要がありました。私はそれが同期の問題だと思います。 – Vahe

答えて

0

私の問題は実行されていないコードではなく、データを取得する非同期の性質です。

タイムアウトを追加すると問題が解決しました。

setTimeout(function(){ 
       $('#elem').selectbox("detach"); 
       $('#elem').selectbox("attach"); 
       }, 10); 

HTMLスクリプト

$(function() { 
      $('#elem').selectbox("attach"); 
     }); 

ドロップダウンコードを取得 - HTTPS - プラグインの元のページが利用できない角度コントローラに常駐する

$http.get('some json resource').success(function(data){ 
      $scope.States = data; 
      $scope.abbreviation = data[0].abbreviation; 

      setTimeout(function(){ 
       $('#elem').val($scope.abbreviation); 
       $('#elem').selectbox("detach"); 
       $('#elem').selectbox("attach"); 
      }, 10); 

     }); 
+1

あなたのドロップダウンの人口にコールバックがないのはなぜですか?私はあなたができるタイムアウトから逸脱する方が常に良いと思う。 – Adjit

+0

あなたの提案をありがとう。私の場合、新しいコールバックを持つようにライブラリを修正することを提案していますか?可能であれば、あなたが提供できる例はありますか? – Vahe

+0

私はあなたのプログラム構造について本当に分かりませんので、あなたが文脈を提供し、あなたのプログラムであなたのプログラムで 'attach'と' detach'を実行しようとしているところを示すことができれば助けになるでしょう – Adjit

関連する問題