1
我通過jsonp獲取以下對象。這是結構:打印具有循環的jsonp對象屬性
"item1": {
"child1": {
"nr": 123,
"money": "USD",
"Date": "12.12.2016, 17:00",
"asw1": 13,
"SpecialField": 33,
"another": 11,
"climbedSince": 1,
"rfeeew": 0,
"dfffe": 10
},
"child2": {
"nr": 123,
"money": "EUR",
"Date": "01.01.2017, 17:00",
"asw1": 11,
"SpecialField": 11,
"another": 11,
"climbedSince": 1,
"rfeeew": 0,
"dfffe": 10
}
},
"item2": {
"child1": {
"nr": 552,
"money": "USD",
"Date": "12.4.2016, 13:00",
"asw1": 13,
"SpecialField": 33,
"another": 44,
"climbedSince": 1,
"rfeeew": 0,
"dfffe": 10
},
"child2": {
"nr": 343,
"money": "EUR",
"Date": "01.01.2017, 17:00",
"asw1": 11,
"SpecialField": 67,
"another": 11,
"climbedSince": 1,
"rfeeew": 0,
"dfffe": 10
}
}
這是我的代碼。
<script>
\t function getApiData(tld, callback) {
\t $.ajax({
\t \t url: 'https://www.website.com/api',
\t \t dataType: 'jsonp',
\t \t success: function(data) {
\t \t \t callback(data);
\t \t \t console.log(data);
\t \t },
\t \t error: function() {
\t \t \t console.error('Could not get lottery jackpots!');
\t \t }
\t });
}
function drawApiData() {
\t var now = new Date();
\t getApiData('com', function(theStuff){
\t \t $.each(theStuff, function(id, value) {
\t \t \t var checkStuff=[];
\t \t \t if($.inArray(id, checkStuff)==-1){
\t \t \t \t checkStuff.push(id); \t
\t \t \t $('#main2').append('Field: '+id+'<br/');
\t \t \t }
\t \t });
\t });
}
drawAllData();
</script>
我想用打印(附加)屏幕情侶值的循環,爲許多項目的對象有(它不是靜態的,而是結構始終是相同)。
我可以打印item1,item2但我無法設法訪問第二級。
我想打印的是例如「Date」+「SpecialField」的時間。
非常感謝您的幫助! :)
'$。每()'是*遍歷一個jQuery對象*不是 – RomanPerekhrest