我想将我的数据绑定(bind)到 owl carousel。我可以将它与 json 数据路径绑定(bind)。 像这样:
$("#owl-demo").owlCarousel({
jsonPath: 'json/customData.json',
jsonSuccess: customDataSuccess});
function customDataSuccess(data) {
var content = "";
for (var i in data["items"]) {
var img = data["items"][i].img;
var alt = data["items"][i].alt;
content += "<img src=\"" + img + "\" alt=\"" + alt + "\">"
}
$("#owl-demo").html(content);
}
但是,我正在使用ajax。我不想获取 json 文件。 我的代码:
jQuery.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "DetailSrv.asmx/GetDetails",
data: JSON.stringify({ id: categoryID }),
dataType: "json",
success: function (sonuc) {
jsonData = JSON.parse(sonuc.d);
console.log(jsonData);
var html = "";
for (var i = 0; i < jsonData.length; i++) {
var itemData = jsonData[i];
}
}});
如何在 custonDataSuccess(data) 函数上使用此 jsonData?
最佳答案
试试这个。 我将 owl 与 Mustache.js 结合使用,并以其他方式对内容进行模板化,但我想这也适合您。
$("#owl-demo").data('owlCarousel').addItem(content);
关于jquery - Owl轮播动态数据与json绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31379036/