2016-10-07 98 views
0

我想使用x-editable編輯下拉列表(選擇)的每個元素。jQuery X-editable更新下拉列表

<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-editable會顯示所有選項。這裏newValue =「test1 test2」。

enter image description here

有沒有一種方式,X編輯能夠編輯在選擇每一個選項?

=>http://jsfiddle.net/

THX!

+0

你也許意味着要更換新的一個,你在響應 – Franco

+0

是越來越選項..但似乎X編輯不與選擇 –

+0

有工作有幾種方法可以做到這一點。如果您從數據庫中獲取值,那麼我需要查看您的響應是什麼樣的。如果您不想手動將選項添加到下拉列表中,則標記將有所不同。 – Franco

回答

0

首先您需要一個服務器端腳本來保存編輯的值。

your_saving_script.php 

如果要設置的值手動,那麼你可以這樣做:

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

如果從服務器端獲取數據,你需要一個腳本來獲取你的數據:

your_json.php 

服務器端腳本

<?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' 
});