2016-10-07 5 views
0

x-editable을 사용하여 드롭 다운 (선택)의 각 요소를 편집하고 싶습니다.jQuery X 편집 가능한 업데이트 드롭 다운

<div style="margin: 150px"> 
    <select id="list1"> 
    <option value="1">test1</option> 
    <option value="2">test2</option> 
    </select> 
</div> 

$('#list1').editable({ 
    success: function(response, newValue) { 
    console.log("response: "+response+' val: '+newValue); 
    } 
}); 

x-editable은 문자열의 모든 옵션을 병합하는 것으로 보입니다. 옵션을 선택하면 x 편집 가능으로 모든 옵션이 표시됩니다. 여기서 newValue = "test1 test2".

enter image description here

X-편집 방법은 선택의 각 옵션을 편집 할 수가되어 있습니까?

=>http://jsfiddle.net/

들으!

+0

당신은 아마 당신이 응답 – Franco

+0

예에 점점 새로운 하나의 옵션을 대체하려는 건 아니 겠죠 ..하지만 X-편집이 선택 –

+0

와 함께 작동하지 않는 것 같다 그렇게하는 데는 몇 가지 방법이 있습니다. 데이터베이스에서 값을 가져 오는 경우 응답이 어떻게 표시되는지 확인해야합니다. 대신 드롭 다운 목록에 옵션을 수동으로 추가하려면 마크 업이 다를 수 있습니다. – Franco

답변

0

먼저 편집 된 값을 저장하려면 서버 측 스크립트가 필요합니다. 당신은 수동 다음 값을 설정하는 경우

your_saving_script.php 

당신이 할 수 있습니다

your_json.php 
:

$('#list1').editable('http://www.example.com/your_saving_script.php', { 
    data : " {'1':'Test 1','2':'Test 2', 'selected':'1'}", 
    type : 'select', 
    submit : 'OK' 
}); 

서버 측에서 데이터를 가져 오는 경우 당신은 당신의 데이터를 가져 오기 위해 스크립트를 필요

서버 측 스크립트

<?php 
/* http://www.example.com/your_json.php */ 
// fetch data from database and return the values in the array 
$array['1'] = 'Test 1'; 
$array['2'] = 'Test 2'; 
$array['selected'] = '1'; 
echo json_encode($array); 
?> 
,

그리고 :

$('#list1').editable('http://www.example.com/your_saving_script.php', { 
    loadurl : 'http://www.example.com/your_json.php', 
    type : 'select', 
    submit : 'OK' 
}); 
관련 문제