Rob*_*bin 2 javascript jquery drop-down-menu x-editable
我正在尝试在显示之前更改x-editable源数据,以便即使源更改,我的下拉菜单条目也始终保持新鲜.
这是一个解释的链接:http://jsfiddle.net/XN7np/3/
// my source that can change over time
var source = [{'value': 1, 'text': 'fine'}, {'value': 2, 'text': 'bad'}];
$('#my_select').editable({
'mode' : 'inline',
'source': source,
});
$('#my_select').on('shown', function(ev, editable) {
// now changing my source just before dropdown is shown
source = [{'value': 1, 'text': 'GOOD'}, {'value': 2, 'text': 'FU'}];
//$(editable).editable('option', 'source', source); NOT WORKING
//$('#my_select').editable('option', 'source', source); NOT WORKING
//$(this).editable('option', 'source', source); NOT WORKING
});
Run Code Online (Sandbox Code Playgroud)
任何的想法?
我没有在文档中看到它,但您可以将函数传递给source参数,如下所示:
var source = [{'value': 1, 'text': 'fine'}, {'value': 2, 'text': 'bad'}];
$('#my_select').editable({
'mode' : 'inline',
'source': function() {
return source;
},
});
Run Code Online (Sandbox Code Playgroud)
这样它总是使用更新的源数组.我更新了你的小提琴:http: //jsfiddle.net/XN7np/4/