2017-01-05 25 views
1

Select2 4.0.3を1回選択して使用しています。select2で選択する値を取得できません:選択

変更イベントがトリガーされる前に値を選択しようとしています(ユーザーが選択して割り当てられる値)。

これは私がイベントをフックするために使用していたコードであり、私はテスト何:

$('#mycombo').on("select2:selecting", function (evt) { 

    var $this = $(this); 

    console.log($this.val()); // This return the current value 
    console.log(evt.data); // This return unassigned 
    console.log(evt.params); // This return unassigned 
    console.log(evt.args); // This return unassigned 
    console.log(evt.object); // This return unassigned  
}) 

は、私もここでFire callback when selection was made with select2 4.0, and retrieve the value of last selection例を試してみましたが、それは選択のように見えるとイベントが同時にトリガされる変更します。

私は紛失しており、いかなる助けも本当に高く評価されます。あなたは、のparamsであり、その情報を持っているこの

$('#mycombo').on("select2:selecting", function (evt) { 
    console.log(evt.params.args.data); // this returns the object of 
}) 

で、たとえばしようとすると、そのデータに使用すると、.textセクションまたは.IDような何かを行うことができますし、オプションまたはのテキストを持つことができます

答えて

2

それぞれ値。

evt.params.args.data.text 
+0

私はそれを試みましたが、** evt.params **は割り当てられていません。 – CrApHeR

+0

ここには実例があります http://codepen.io/anon/pen/egmraE?editors=1010 – xploshioOn

+0

私はあなたの答えを受け入れるとマークし、私は再びコードをチェックします。ありがとう! – CrApHeR

関連する問題