How do I add an attribute rel=blah to a JSON string? I have the following in a JSON file:
[
{"image":"/images/image1.png", "link":"http://mylink.com"},
{"image":"/images/image2.png", "link":"http://mylink.com"},
{"image":"/images/image3.png", "link":"http://mylink.com"}
]
The output creates the images and links I want on the page. But I’ve tried to add a rel attribute like following:
{"image":"/images/image3.png", "link":{"rel":"blah","href":"http://mylink.com"}}
{"image":"/images/image3.png", "link":{"rel":"blah","uri":"http://mylink.com"}}
but the output was always the same: <a href="object Object"> Seems like a simple thing but I can’t seem to find the right syntax anywhere.
The piece of the image scrubber javascript that produces the image/link is this:
setImage: function(index) {
this.element.empty();
var anchor = new Element('a', {
'href': this.imageList[index].link
});
this.images[index].inject(anchor);
anchor.inject(this.element);
this.oldIndex = index;
},
This is a question about Javascript, not JSON. You have to rewrite the function, which generates the HTML output, for your new object structure. Now I don’t know what you’re working with there, but from the function you posted, this is my guess what you have to change: