2017-07-31 6 views
0

属性のプロファイルを持つオブジェクトを返すAjax呼び出しがあります。これらのプロファイルのコレクションを使用して<form:select>で複数の値を選択するにはどうすればよいですか。複数の値をフォームで選択する方法:ajaxレスポンスを使用して選択する

$.ajax({ 
     ... // some omitted codes // ... 

     success : function(response) { 
      response.profiles // collection of profiles 
     } 


<form:select id="profile" path="profiles" 
     items="${profilelist}" multiple="true" itemValue="id" itemLabel="type"/> 

答えて

0

これは重複している質問のようですが、常に最初にあなたの問題について同様の質問があるかどうかを確認してください。

フレームワークを使用している場合は、それに基づいてオプションでデータを取得できるため、使用しているフレームワークも指定していません。

ここで私はすべてのフレームワークなしのために答えています、

<form:select id="profile" path="profiles" 
     items="${profilelist}" multiple="true" itemValue="id" itemLabel="type"/> 

AJAX呼び出しは、このようなものである必要があり、

$.ajax({ 
     type: "GET", 
     url: "http://.......api/1/AbsenceType", 
     dataType: "json", 
     success: function (data) { 

     // Get select 
     var select = document.getElementById('profiles'); 

    // Add options 
     for (var i in data) { 
     $(select).append('<option value=' + data[i] + '>' + data[i] + 
    '</option>'); 

    // Set selected value 
    $(select).val(data[1]); 
    } 
     } 

は、この情報がお役に立てば幸いです。

関連する問題