Last active
August 29, 2015 14:23
-
-
Save mdunbavan/56d7bf823f7f1f48ec1e to your computer and use it in GitHub Desktop.
Getting objects in json.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| work_content: Array[4] | |
| Object 0: | |
| acf_fc_layout: "content_area" | |
| text: "<p>test text</p>↵" | |
| Object 1: Object | |
| acf_fc_layout: "gallery" | |
| images: | |
| Object 2: Object | |
| acf_fc_layout: "full_screen_video" | |
| video_url: "<iframe width="560" type="text/html" height="315" id="windows" src="//www.youtube.com/embed/1S7He-ShRLg?version=3&enablejsapi=1&html5=1" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>" | |
| Object 3: Object | |
| acf_fc_layout: "2_column_images" | |
| image_1: Object | |
| image_2: Object |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| success: function ( dataS ) { | |
| //List some global variables here to fetch post data | |
| // We use base as our global object to find resources we need | |
| var base = dataS[0]; | |
| console.log(base); | |
| var postContent = base.content; | |
| var postTitle = base.title; | |
| // Main Image ACF object | |
| var featuredImage = base.meta.main_image; | |
| // Gallery ACF object | |
| var nodes = base.meta.work_content; | |
| // Simple ACF object | |
| //var textArea = base.meta.work_content[1]; | |
| var items = []; | |
| var layoutNames = []; | |
| for(var i = 0; i < nodes.length; i++) | |
| { | |
| var layout = nodes[i]; | |
| layoutNames.push(layout.acf_fc_layout); | |
| //console.log(layout); | |
| // items.push( layout.acf_fc_layout['gallery']); | |
| // console.log(layout); | |
| }; | |
| console.log(layoutNames); | |
| // This outputs below | |
| // Object {acf_fc_layout: "content_area", text: "<p>test text</p>↵"}, | |
| // Object {acf_fc_layout: "gallery", images: Array[1]}, | |
| // Object {acf_fc_layout: "full_screen_video", video_url: "<iframe width="560" type="text/h…llowfullscreen allowfullscreen></iframe>"}, | |
| // Object {acf_fc_layout: "2_column_images", image_1: Object, image_2: Object}acf_fc_layout: "2_column_images"image_1: Objectimage_2: Object__proto__: Object} | |
| $(layoutNames).each(function (){ | |
| // This now loops through all objects from layouts and retrieves them. | |
| for(var i = 0; i < nodes.length; i++) | |
| { | |
| var layout = nodes[i]; | |
| //if( layout.acf_fc_layout==$(this).val() ); | |
| if ( layout.acf_fc_layout == $(this).val() && $(this).val() == "gallery"){}; | |
| //Perform Operation either image / video / page layout | |
| //console.log(layout); | |
| }; | |
| }); | |
| // $('<div>', { | |
| // "class":'loaded', | |
| // html:items.join('') | |
| // }).appendTo(projectContainer); | |
| }, | |
| cache: false | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment