This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
I tried doing a search first cause I was sure that this had to have been discussed upteen times.
I have a json value coming back with information. One property is set via an Enum in Java, so in the json it is just a String. Based on that String I want to set my radio buttons to have the one checked for that value. I am using Mustache/ICanHaz templating that is generating the radio buttons, but all I will have in the template is {{visibility}} basically the String value and there isn't any javascript in the template., the template is rendered from JavaScript and the html is stored in a var before I add it to a div via html(contentsFromTemplateRendering).
Thanks
With all your help I have been making some great progress on my app. I might one day call myself a web developer. But very quietly so no one else hears.
The HTML still looks the same, so the part about ICanHaz only has an affect that I get the String value via its name {{visibility}} which just gets replaced with the value from the JSON.
Here is the HTML
Here is a picture of the radio buttons in the FancyBox I use.
Bear - I was thinking that people didn't answer because it was such and easy solution that it was a dumb question that everyone thought I was just plain lazy. ;)
Actually, that is pretty looking. Yeah the high level variable "temp" isn't pretty, but the rest is slick. It is why you are the expert and me just the learner.
"Sucks having to add that into your object"
Do you mean the js code into the template/html? or that goes in one of my .js files, or included in my json. The JSON doesn't sound right, but I think you mean in my template. Unless you tell me otherwise.
where the visibilityFunction is part of the JSON object. iCanHaz and mustache allows functions in data objects and calling them from the template. Looks like I will go down that path of adding a function after I get the data from the server.
Thanks
Mark
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15362
6
posted
0
Well functions are not in JSON, adding the function turns it into an object literal. Run it through JSON.parse() and you will be out of luck.
Eric Pascarello wrote:Well functions are not in JSON, adding the function turns it into an object literal. Run it through JSON.parse() and you will be out of luck.
Another reason why I do not like it my solution.
Eric
Actually the template takes an object, so with that var holding that object I can add a function. When I retrieve the JSON from JQuery .post call it is assigned to a var, which I can then add the function