我正在尝试使用ajax调用从json数组中获取项目列表,并将它们放入复选框列表中。这些物品装得很好,但它们没有jquery手机造型。
$(document).ready(function(){
jQuery.support.cors = true;
$.ajax({
type: 'GET',
url: "https://evalue.internationaldelivers.com/service_kb_cust/OCCAPI/Mobile/json/f9496ab3c3764fd0ae201de76c71608f/OCC_GetFiltersObj",
dataType: "json",
contentType: 'application/json',
crossDomain: true,
async: true,
cache: false,
timeout: 30000,
success: function (data, status, xhr) {
for (var i=0, len=data.OCC_FiltersObj_Cust.length; i < len; i++) {
$("#filterpanel fieldset").append("<input type='checkbox' name='checkbox-2' id="+data.OCC_FiltersObj_Cust[i].CustomerID+" class='custom'/>")
$("#filterpanel fieldset").append("<label for="+data.OCC_FiltersObj_Cust[i].CustomerID+">"+data.OCC_FiltersObj_Cust[i].CustomerName+"</label>")
}
},
complete: function (xhr, status) {
// Indicate complete
},
error: function (xhr, status, error) {
// Assert an error
}
});
});
有人可以帮助我吗?
答案 0 :(得分:0)
你需要在复选框父元素
上调用trigger(“create”)所以试试这个:
success: function (data, status, xhr) {
for (var i=0, len=data.OCC_FiltersObj_Cust.length; i < len; i++) {
$("#filterpanel fieldset").append("<input type='checkbox' name='checkbox-2' id="+data.OCC_FiltersObj_Cust[i].CustomerID+" class='custom'/>")
$("#filterpanel fieldset").append("<label for="+data.OCC_FiltersObj_Cust[i].CustomerID+">"+data.OCC_FiltersObj_Cust[i].CustomerName+"</label>")
}
$("[type='checkbox']").closest("div").trigger("create");
}
答案 1 :(得分:0)
for (var i=0, len=data.OCC_FiltersObj_Cust.length; i < len; i++) {
$("#filterpanel fieldset").append("<input type='checkbox' name='checkbox-2' id="+data.OCC_FiltersObj_Cust[i].CustomerID+" class='custom'/>")
$("#filterpanel fieldset").append("<label for="+data.OCC_FiltersObj_Cust[i].CustomerID+">"+data.OCC_FiltersObj_Cust[i].CustomerName+"</label>")
}
$("#filterpanel fieldset").trigger("create");