I'm pretty new to jQuery and I am trying to achieve the following solution.
I am using a nice image carousel/slider that requires me to have a div on the page containing the images that I want the carousel to use. I want the flexibility to put images in a folder instead of hard coding them, and the images then be displayed, so:
- a folder (img) on my server containing any number of images
- some solution to create a list (array) of the images (their paths)
- the list or array to be used with the carousel, whether it just generates the HTML or not I guess is half the problem!
I appreciate the help!
@RobW - as I said I am learning..
/--- edit: I found a solution using jQuery templates. It may not be the smartest, but here it is:
I created a div that I want the images placed in:
<div id="imageContainer"></div>
<!-- Create template -->
<script id="imageTemplate" type="text/x-jquery-tmpl">
<img id="imageItem" src='../PublishingImages/${Name}' alt="${Desc}" />
</script>
<!-- Get data -->
<script type="text/javascript">
$(document).ready(function () {
$.getJSON(
'../_vti_bin/ListData.svc/Images',
function(data) {
$('#imageTemplate') //select the template
.tmpl(data.d.results) //bind it to the data
.appendTo('#imageContainer'); //render the output
});
});
</script>