0

redips javascriptを使用してドラッグアンドドロップシステムを作成しています。

これは、html と php を使用してデータを生成するスクリプトです。

<div id="base">  
   <table>
     <tbody>
       <?php 
          foreach($deviceID as $row)
          { 
             echo '<tr><td><div class="drag">'.$row['description'].'<input type="hidden" id="bus" value="'.$row['description'].'"></div></td></tr>'; 
          }
        ?>
       </tbody>
    </table>
</div>

これは私のjavascriptファイルの断片です。

var redips_init;
redips_init = function () {
    // reference to the REDIPS.drag
    var rd = REDIPS.drag;
    // initialization
    rd.init();
        rd.drop_option = 'shift';
    rd.animation_shift = true;

        rd.myhandler_dropped = function () {            
            alert($('#bus').val());
        }
};
4

2 に答える 2

0

I am not good with php but what i usually do in jsp is create a local index variable and append it to each of the ID attribute in the loop.

So your code would look something like this

  <?php 
      $index=0;    
      foreach($deviceID as $row)
          { 
             echo '<tr><td><div class="drag">'.$row['description'].'<input type="hidden" id="bus'.$index++.'" value="'.$row['description'].'"></div></td></tr>'; 
          }
        ?>

In javascript, your dragAndDrop event should return an index location by which u can get appropriate value.

Now you can use this dynamic ID in your JavaScript to do whatever you want to do.

于 2012-04-18T09:30:49.860 に答える
0

REDIPS.drag には、テーブル内のすべての DIV 要素をスキャンし、結果をクエリ文字列またはJSONオブジェクトとして返すためのsave_content()メソッドが含まれています。入力パラメーターは、テーブル ID と返される結果のタイプです (デフォルトはクエリ文字列です)。これで十分でない場合は、save_content() ソースを検索してカスタマイズできます。メソッドは単純で、いくつかのループを使用してテーブルの内容をスキャンします。

一方、ドロップされた DIV 要素の ID を知りたい場合は、myhandler_droppedイベント ハンドラー内に記述できます。コード スニペットは次のとおりです。

rd.myhandler_dropped = function () {
    // define DIV id
    var id = rd.obj.id;
    // write DIV id to the console
    console.log(id)
};

この回答がお役に立てば幸いです。

于 2012-06-29T11:56:59.333 に答える