0

私はこれをしようとしています:

2つのフィールドがあります1.日付-jquerydatepickerを使用します2.ドロップダウン-学生IDが入力されます

したがって、日付を選択すると、2012年3月9日と言うと、その日にすべての学生IDが表示されます(たとえば15個)。次に、日付を2012年4月9日に変更すると、その学生のみのIDを取得する必要があります。その日に存在します(たとえば29人)

私が行ったのは、次のようにデータベースをクエリするためにajax呼び出しを行ったということです。

$('#date_selected').blur(function(){
$.ajax({
//query database and get the array of student id present on that date
//but from jquery how do i know populate my dropdown ?
//i would probably get the results json encoded
});
});

データの取得に関する問題はありません。私が持っているarray(json)を使用してドロップダウンにデータを入力する方法を知りたいだけです。

4

2 に答える 2

2

これをajax成功関数内で使用します。

data = $.parseJSON(data);

var select_fields = data.selectf;

var select_id = "/*ID OF SELECT FIELD*/";

$('#'+select_id+' option').remove();

for(var x  in select_fields){
    $('#'+select_id).append($('<option value="'+select_fields[x]['value']+'">'+select_fields[x]['name']+'</option>'));
}
于 2012-09-03T06:41:46.357 に答える
1

あなたはdatepickeronselectメソッドを使用することができます

 $('#date_selected').datepicker({
    onSelect:function (selectedDate) {
       //make your jquery ajax post here
    }
   });
于 2012-09-03T06:39:42.800 に答える