У меня есть данные JSON, и я хочу получить данные из определенного атрибута (recordstatus). Проблема в том, что путь к узлу - x.result.68089.recordstatus, но 68089 не работает в вызове jQuery и является динамическим, каждая запись в качестве другого номера. Есть ли способ найти значение recordstatus напрямую?
Файл JS:
function getObjects(obj, key, val) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == 'object') {
objects = objects.concat(getObjects(obj[i], key, val));
} else if (i == key && obj[key] == val) {
objects.push(obj);
}
}
return objects;
}
jQuery('a[id^="link"]',window.parent.document).each(function(index) {
var objRECSTATUS=jQuery(this);
var url=decodeURIComponent(objRECSTATUS.attr('href'));
var l=jQuery(this).html();
if (l.indexOf("print")>0) {
var pmid= getParameterByName("pmid", url);
jQuery.ajax({
type: "GET",
url: "data.json",
dataType: 'json',
success: function(data) {
console.log(data);
if (data.result[*].recordstatus == 26) {
console.log("OK 1");
objRECSTATUS.removeAttr("href",json.header.version);
objRECSTATUS.replaceWith(" <span><img src='http://wiki.apache.org/wiki/modernized/img/alert.png' Status 26)</span> Status 26");
}
else if
(data.header.type == 'book')
else {
objRECSTATUS.hide();
console.log("KO");
}
},
error: function(xhr, status, error) {
objRECSTATUS.hide();
}
});
}
} );
}
JSON FILE
{
"header": {
"type": "cdrom",
"version": "6.3"
},
"result": {
"uids": [
"268089"
],
"268089": {
"uid": "268089",
"pubdate": "1999",
"paperpubdate": "2012",
"source": "History",
"authors": [
{
"name": "John",
"authtype": "Author",
"clusterid": ""
}
],
"lastauthor": "David",
"title": "World History.",
"sorttitle": "world history",
"volume": "2",
"issue": "9",
"pages": "365",
"lang": [
"eng"
],
"nlmuniqueid": "89",
"issn": "1947-3211",
"essn": "14680-2199",
"pubtype": [
"Book"
],
"status": "Online",
"recordstatus": "26",
"cover": ""
}
}
}
Большое спасибо за помощь