我有一个具有以下结构的 JSON API 响应
[
{
title: "top1",
sections: [
{
section_title: "section1",
content: [
{
content_title: "title1",
content_id: "id1"
},
{
content_title: "title2",
content_id: "id2"
}
]
},
{
section_title: "section2",
content: [
{
content_title: "title3",
content_id: "id3"
},
{
content_title: "title4",
content_id: "id4"
}
]
}
]
}, {
title: "top2",
sections: [...]
},
...
]
Run Code Online (Sandbox Code Playgroud)
我还有一小部分内容 ID arr2 = ['id2','id3']。我需要从 API 请求中搜索数据以查找包含在arr2.
我有一些可用的 lodash 代码,但我的嵌套 forEach 方法似乎不是最有效的方法:
_.forEach(response, function(top) {
_.forEach(top.sections, function(section) {
_.forEach(section.content, …Run Code Online (Sandbox Code Playgroud) 我有一个页面,使用jQuery AJAX get请求从XML文件加载产品信息.这适用于FF和Chrome,但内容不会在IE中加载.但是,它会在打开开发人员窗口并刷新页面后加载数据!有谁知道为什么?
这是我的jQuery AJAX请求:
//Load the xml file
$.ajax({
type: "GET",
url: "xml/" + cat + ".xml",
dataType: ($.browser.msie) ? "text" : "xml",
success: function(data) {
alert('xml successfully loaded');
var xml;
if (typeof data == "string") {
xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
xml.loadXML(data);
} else {
xml = data;
}
//Get total number of products in the category
$(xml).find('dataroot').each(function() {
var pTemp = $(this).attr('count');
catName = $(this).attr('catTitle');
console.log(catName);
pTotal = Number(pTemp);
});
//Fill the correct entries onto …Run Code Online (Sandbox Code Playgroud)