在 ajax 调用后,使用新数据重新填充图像选取器选择控件
Repopulating Image Picker select control with new data after ajax call
我正在使用这个图像选择器 jQuery 插件 (http://rvera.github.io/image-picker/),我遇到了以下问题:
在ajax 调用后使用新数据重新填充选择控件。
$.ajax({
type: "GET",
url: requestURL,
dataType: 'json',
success: function(result)
{
$.each(result, function(i, obj) {
console.log(obj.description);
$('#cake-filling-types-select')
.append($("<option data-img-src='" + obj.image + "'></option>")
.attr("value", obj.code)
.text(obj.description));
});
$("#cake-filling-types-select").imagepicker({
show_label : true
});
$("#cake-filling-types-select").data("picker").sync_picker_with_select();
}});
有关更多详细信息,请在此处找到问题:https://github.com/rvera/image-picker/issues/79
谢谢。
问题解决了。在 @ArmindoMaurits @ GitHub 的帮助下,因此使用 ' $("#cake-filling-types-select").empty();' 可以清除此插件选择。
此外,对于某些项目未进入选择控件的另一个问题,我发现这些项目缺少 img src。
更新的工作代码:
`$.ajax({
type: "GET",
url: requestURL,
dataType: 'json',
success: function(result){
$("#cake-filling-types-select").empty();
$.each(result, function(i, obj) {
if(obj.image != null)
{
var imgSrc = obj.image;
}else{
imgSrc = '';
}
$('#cake-filling-types-select')
.append($("<option data-img-src='" + imgSrc + "'></option>")
.attr("value", obj.code)
.text(obj.description));
});
$("#cake-filling-types-select").imagepicker({
show_label : true
});
}});`
相关文章:
- 使用数据库中的图像填充dropzone.js删除图像的问题
- 使用D3用背景图像填充svg
- 用网址图像填充输入
- 如何在paperJS中用图像填充矩形
- Javascript/HTML5使用图像填充画布
- 单击以使用图像填充画布背景
- 使图像填充剩余的垂直空间,无需滚动
- D3使用图案用图像填充形状
- 用图像填充ul li
- 使图像填充屏幕,在不同分辨率下保持宽高比
- 我如何使图像填充90%的屏幕而不失去长宽比
- 上传的图像填充画布Javascript
- Javascript:用数组中的图像填充表
- 为什么在iOS4中http://justplay.thefa.com上的svg图像填充是颠倒的
- Raphael Js不能用图像填充路径
- 为什么W3验证需要为图像填充alt和src属性?
- 使图像填充100%宽度的容器
- 如何将图像填充为链接,这些链接都作为JSON对象存储在数组中
- 用按钮图像填充表单文本字段
- SVG路径绘制和图像填充