Please bear with me here because I am a total beginner when it comes to JSON and AJAX and abstracting jQuery.

So far I have gotten to a point where I can loop through an array that contains the IDs of all of my first level links, and fetch the data from my JSON file that corresponds with that same index.

OK! So:

JSON file can be seen here: http://bmgz.rtcgraphics.com/../linking-to-another-index-in-json-file/wp-content/themes/bmgz/data/whatwedo.js

Demo website can be viewed here: http://bmgz.rtcgraphics.com/#3

jQuery:

var slugArray = [
    '#project-management',
    '#economic-incentives',
    '#site-selection',
    '#stakeholder-engagement-and-events',
    '#lobbying-and-advocacy',
    '#public-policy-and-issues-management',
    '#digital-communications',
    '#event-and-trade-show-materials',
    '#presentation-and-print-design'
]
function getWWD(){
  $.getJSON('../linking-to-another-index-in-json-file/wp-content/themes/bmgz/data/whatwedo.js', function(result){
    $.each(slugArray, function(i, selection){
      $(selection).click(function(){
        $("#w-dropdown header img").attr('src', result[i].icon);
        $("#w-dropdown h4").html(result[i].name);
        $("#w-copy header").html(result[i].name);
        $(result[i].cousins).each(function(index, item){
            $(".wwd-ul").append($(document.createElement('li')).addClass('wwd-li').text(item));
        });
        console.log($(".wwd-li").text());
        $("#w-copy p").html(result[i].copy);
        $('#chalkboard').css({"background-image":"url("+result[i].cover+")"});
        $("#wwd-sub-icons img:first-child").attr('src', result[i].subicon1);
        $("#wwd-sub-icons img:last-child").attr('src', result[i].subicon2);
      });
    });
  });
};
getWWD();

What I’d like to do is the following:

In the subpages that get generated by the getWDD(); function:

  • To check the img src of the $(“#wwd-sub-icons img:first-child”) and $(“#wwd-sub-icons img:last-child”) and, depending on the src, force the index to be 1, 4, or 7 and have all subpage content jump to the JSON values for the object at that index.

  • To have the generated list items with class “wwd-li” exhibit the following behavior when clicked: Grab the text that’s inside the list item and use this to find the index inside the JSON file where the result[i].name is the same as the text in the li, then adjust the index of all of the other on-page data to match that new index.

Any and all guidance or tutorials would be appreciated!!!! Thank you!!

Read more here: Linking to another index in JSON file


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , ,

Wordpress related questions and answers: