【发布时间】:2017-10-12 19:43:57
【问题描述】:
我已经让xeditable 和select2 使用api 作为源调用,除了以下之外,一切都很好。
提交select2下拉列表后,表格的值显示为EMPTY,需要刷新页面才能更新为正确的值。
有谁知道如何将值更新为选定的select2 下拉值?
我的html:
<td class="eo_role"><a href="#" data-pk={{r.pk}} data-type="select2" data-url="/api/entry/{{r.pk}}/"
data-name="eo_role" data-title="Enter EO_role">{{r.eo_role}}</a></td>
这是我的 JS:
$('#example .eo_role a').editable( {
params: function(params) { //params already contain `name`, `value` and `pk`
var data = {};
data[params.name] = params.value;
return data;
},
source: 'http://localhost:8000/api/eo_role/select_two_data/',
tpl: '<select></select>',
ajaxOptions: {
type: 'put'
},
select2: {
cacheDatasource:true,
width: '150px',
id: function(pk) {
return pk.id;
},
ajax: {
url: 'http://localhost:8000/api/eo_role/select_two_data/',
dataType: "json",
type: 'GET',
processResults: function(item) {return item;}
}
},
formatSelection: function (item) {
return item.text;
},
formatResult: function (item) {
return item.text;
},
templateResult: function (item) {
return item.text;
},
templateSelection : function (item) {
return item.text;
},
});
再次 - 一切正常(数据库更新、下拉列表填充等),但 <td> 在提交下拉列表后更新为 "EMPTY" - 需要刷新页面以显示正确的值。
【问题讨论】:
-
我尝试了类似的链接问题/解决方案,但没有奏效。 stackoverflow.com/questions/28190106/…
标签: javascript jquery-select2 x-editable