New to all of this, but the jest of the program is for json data to populate a listview dynamically as well as when user clicks on the listview href it sends them to the page and dynamically loads the content for that specific page (text, image, and any url's) into specific separate divs. The key is to be dynamic using json data. Please help.
This is my JavaScript/HTML code as well as JSON data:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"><link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<!--<script type="text/javascript" src="cordova.js"></script>-->
<script>
$(document).on("pagebeforeshow", "#ccc", function() {
$.getJSON('js.json', function(data) {
var output = "";
var newpage = "";
for(var i in data.mydata) {
output += "<li>" +
"<a href=\"#page" + data.mydata[i].myId + "\">" +
"<h3>" + data.mydata[i].thename + "</h3>" +
"<p>" + data.mydata[i].description + "</p>" + "</a>" +
"</li>";
if ($("#page" + data.mydata[i].myId).length == 0 && (data.mydata[i].myId == 0)) {
newpage += "<div data-role=\"page\" id=\"page" + data.mydata[i].myId + "\">";
newpage += "<div data-role=\"header\">" + "<a data-role=\"button\" data-rel=\"back\" data-icon=\"back\">Back</a>" + "<h3>" + data.mydata[i].thename + "</h3></div>";
newpage += "<div role=\"main\" class=\"ui-content\">" + "<h1 >What type of Nursing is right for you?</h1>" +"</div>";
//how to grab nested objects with for loop such as link
// for loop that grabs myId AS WELL AS LINKid/textid/pictureID and displays
newpage += "<div data-role=\"footer\">" + "<h1>0Future Nurses</h1>"+ "<p class= \"center\">Telephone: <br/>" +
+"</div>"+"</div>";
}
output += "";
newpage += "";
$('body').append(newpage);
$("#mylist").html(output).listview('refresh');
};
});
});
</script>
</head>
<body>
<div data-role="page" id="ccc">
<div data-role= "header">
<h1>Future Nursings</h1>
<h2 class = "center">Action Coalition</h2>
<div role="main" class="ui-content">
<ul id="mylist" data-role="listview" data-inset="true">
</ul>
</div>
</div>
<div data-role="footer" >
<h1>Future Nurses</h1>
<p class= "center">Telephone: <br/>
Email: </p>
<h1>Get Social with us!</h1>
<div class = "centerButton">
<a href = "#" class = "ui-btn ui-corner-all ui-shadow ui-btn-inline">Facebook</a></button><br/>
<a href = "#" class = "ui-btn ui-corner-all ui-shadow ui-btn-inline">Twitter</a></button><br/>
<a href = "#" class = "ui-btn ui-corner-all ui-shadow ui-btn-inline">Indeed</a></button><br/>
<a href = "#" class = "ui-btn ui-corner-all ui-shadow ui-btn-inline">Join Us</a></button><br/>
</div>
</div>
</div>
<div data-role="page" id="ccc">
<div data-role= "header">
<h1>Future Nurses</h1>
<h2 class = "center">Action Coalition</h2>
<div role="main" class="ui-content">
<ul id="mylist" data-role="listview" data-inset="true">
</ul>
</div>
</div>
<div data-role="footer" >
<h1>Future Nurses </h1>
<p class= "center">Telephone: <br/>
Email: </p>
<h1>Get Social with us!</h1>
<div class = "centerButton">
<a href = "#" class = "ui-btn ui-corner-all ui-shadow ui-btn-inline">Facebook</a></button><br/>
<a href = "#" class = "ui-btn ui-corner-all ui-shadow ui-btn-inline">Twitter</a></button><br/>
<a href = "#" class = "ui-btn ui-corner-all ui-shadow ui-btn-inline">Indeed</a></button><br/>
<a href = "#" class = "ui-btn ui-corner-all ui-shadow ui-btn-inline">Join Us</a></button><br/>
</div>
</div>
</div>
</body>
</html>
{
"mydata": [
{
"myId": "0",
"thename": "Is Nursing for You?",
"description": "This is the zero description",
"links":[
"google.com",
"yahoo.com",
"worldstarhiphop.com"
],
"text": [
"random text 0000",
"random text 0000",
"random text 0000"
],
"imgPath": [
"image/0000.png",
"image/0001.png",
"image/0002.png"
],
"article" : [
{
"text": "random article 0",
"img" : "image/0000.png"
},
{
"text": "random article 0",
"img" : "image/0000.png"
}
]
}, {
"myId": "1",
"thename": "Nursing Schools",
"description": "This is the one description",
"links":[
"nordstrom.com",
"google.com",
"aol.com"
],
"text": [
"random text 0001"
],
"imgPath": [
"image/0100.png",
"image/0101.png",
"image/0102.png"
],
"article" : [
{
"text": "random article 0001",
"img" : "image/0001.png"
}
]
}
]
}
Please help I am sufferingXD We all did, we all are, and believe me when I say you aren't done yet.