Train of thought:

1.Write a API for getting values from json, format like: "abc","123","345"

2.Put the widget init into ajax block

 

 

function appendSenderAddress(){
var url = '../foo.do';
$.ajax({
url : url,
type : 'GET',
success : function(data, status){
if(data == 'Please login first'){
return;
}
var statusCode = data.code;
if (statusCode == '0') {
var value = data.foo;
console.log('value: ' + value)
var valueList = value.split(",")
$.each(valueList,function(i,item){
console.log(i,item)
$('#value_list').append("<option value='"+item+"'>"+item+"</option>")
})
initWidget()
} else {
initWidget()
}
}
});

}

 

function initWidget(){
var valuetElem = new Choices('#value_list', {
delimiter: ',',
editItems: true,
maxItemCount: 5,
removeItemButton: true,
});
}

 PS: Must put the widget init into ajax block, if not the widget can't load the values from API