Loading...
Copy code
Close
Permalink
Close
Please tell us why you want to mark the subject as inappropriate.
(Maximum 200 characters)
Report Inappropriate
Cancel
Private Message
From :
guest
To :
Subject :
Content :
Type the characters you see in the picture below.
Send
Cancel
From :
guest
To :
Subject :
Content :
Type the characters you see in the picture below.
Send
Update
Cancel
Feedback
Email ID
Subject :
Comments :
Send
Cancel
Private Message
Type the characters you see in the picture below.
Type the characters you see in the picture below.
Attach files
Desktop
Google Docs
Each Attachment size should not exceed 1.0 MB.
Max no of attachments : 3
Loading User Profile...
guest
Response title
This is preview!
Attachments
Publish
Back to edit
Cancel
(
)
Sign In
New to this Portal? Click here to
Sign up
You can also use the below options to login
Login with Facebook
Login with Google
Login with Yahoo
jQuery
Plugins
UI
Meetups
Forum
Blog
About
Donate
All Forums
Recent Posts
Log In
Search
jQuery
Search
jQuery Forum
Move this topic
Forum :
Getting Started
Using jQuery
Using jQuery Plugins
Using jQuery UI
Developing jQuery Core
Developing jQuery Plugins
Developing jQuery UI
QUnit and Testing
About the jQuery Forum
jQuery Conferences
jQuery Mobile
Developing jQuery Mobile
Sub forum :
Move this topic
Cancel
Using jQuery
Forbidden..
Using to jQuery to access JSON nested array starting with dates
in
Using jQuery
•
4 years ago
I'm attempting to build a ajax call from some json data
jQuery.ajax({
type: "GET",
url: "websiteurl.com",
success: function(data)
{
jQuery.each(data, function(i, val) {
$("#label").append(document.createTextNode(val.label));
$("#url").append(document.createTextNode(val.url));
});
}
});
Here is the jSon (url I've been given)
{
"2019-01-29T00:00:00+00:00": [
{
"type": "refuse",
"label": "Refuse",
"url": "
http://www.exampleurl-one.com"
}
],
"2019-02-05T00:00:00+00:00": [
{
"type": "gardenwaste",
"label": "Garden Waste",
"url": "
http://www.exampleurl-two.com"
},
{
"type": "recycling",
"subtype": "redbox",
"label": "Red Box",
"url": "
http://www.exampleurl-three.com"
},
{
"type": "recycling",
"subtype": "bluebag",
"label": "Blue Bag",
"url": "
http://www.exampleurl-four.com"
},
{
"type": "recycling",
"subtype": "yellowbag",
"label": "Yellow Bag",
"url": "
http://www.exampleurl-five.com"
}
],
"2019-02-12T00:00:00+00:00": [
{
"type": "refuse",
"label": "Refuse",
"url": "
http://www.exampleurl-six.com""
}
],
"calendar": {
"url": "
http://www.exampleurl-seven.com",
"label": "Collection Calendar"
}
}
I'm struggling to get it outputting, because the date will change and I want to show that - but then have the other data following, e.g.
Date: 2019-01-29T00:00:00+00:00 (Formatted which I can do)
Label: Refuse
URL:
http://www.exampleurl-one.com
1
Replies(7)
jakecigar
Re: Using to jQuery to access JSON nested array starting with dates
4 years ago
See
https://jsfiddle.net/jakecigar/by9ak07n/
<--
$.each(data, function(date, array) {
var dt = new Date(date)
if (!isNaN(dt))
$.each(array, function(index, object) {
console.log(dt, object.label, object.url)
})
})
JΛ̊KE
Forbidden..
Re: Re: Using to jQuery to access JSON nested array starting with dates
4 years ago
That's great thanks Jake, what would you recommend to start outputting as HTML?
Leave a comment on jakecigar's reply
jakecigar
Re: Using to jQuery to access JSON nested array starting with dates
4 years ago
I’m not sure what you want it to look like. A table? a list? Are the URLs links or images?
Maybe a <dl><dd><dt> group?
JΛ̊KE
Forbidden..
Re: Re: Using to jQuery to access JSON nested array starting with dates
4 years ago
Sorry table, doh!
I've started with;
$('.table_bins').append('' + object.label + '');
But wonder if that would work for the repeat and have this instead;
$('.table_bins').append(''<table><tr><td>' + object.label + '</td></tr></table>'');
Leave a comment on jakecigar's reply
jakecigar
Re: Using to jQuery to access JSON nested array starting with dates
4 years ago
See
https://jsfiddle.net/jakecigar/by9ak07n/12/
.
JΛ̊KE
Forbidden..
Re: Re: Using to jQuery to access JSON nested array starting with dates
4 years ago
Thanks for the help! Quick one, if I wanted to only show 2 of them e.g. 2 labels and 2 urls
Would the best way be (quick e.g);
$('table.tbody').hide();
$('table.tbody:lt(3)').show();
Or is there a better way?
Leave a comment on jakecigar's reply
jakecigar
Re: Using to jQuery to access JSON nested array starting with dates
4 years ago
Use CSS for that!
https://jsfiddle.net/jakecigar/by9ak07n/21/
<--
tbody tr:nth-child(n+3){display:none}
JΛ̊KE
Leave a comment on jakecigar's reply
Change topic type
Topic Type :
Discussions
Questions
Ideas
Problems
No of days :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Change topic type
Cancel
Link this topic
Provide the permalink of a topic that is related to this topic
Permalink
Save
Close
Reply to ForbiddenChunk's question
Top
Reply
{"z30418453":[14737000007999014,14737000007999049,14737000007999051,14737000007999055],"z2950240":[14737000007996023,14737000007996027,14737000007996029,14737000007996033]}
Statistics
7
Replies
2805
Views
1
Followers
Tags
Cancel
json
Actions
Permalink
Related Posts
Native JSON
JSON array
Autocomplete JSON
JSON error
Json
JSON Question