Hi, this is my first attempt to use MustacheJS with JSON web service in .net
I am currently struggling, I cannot find what I am doing wrong by setting this basic example:
My web service saves the following line:
[ { "ShortDescription":"BOX", "Description":"BOXING", "Id":1 }, { "ShortDescription":"EPL", "Description":"ENGLISH PREMIER LEAGUE", "Id":2 } ]
I checked its syntax with this site: http://json.parser.online.fr/
and here is the HTML code that I use:
google.load("jquery", "1"); google.setOnLoadCallback(function () { $(document).ready( function () { $.ajax({ url: "../data.asmx/geteagues", type: "POST", dataType: "json", data: "", contentType: "application/json; charset=utf-8", success: function (data) { var template = "<h1>{{ShortDescription}} {{Description}}</h1>"; var html = Mustache.render(template, data); $('#sampleArea').html(html); alert(html); } }) } ) });
I am sending all the JS code since I am not very good at javascript, basically I want to always download the latest version of JQuery from Google, and then work with my WS call.
The problem is that when I put a breakpoint on the following line:
var html = Mustache.render(template, data);
I see that the template is installed normally, like the data, the same value as above, but the .render function returns:
I don't seem to like the data.
So far, all the examples I've seen for embedded data have the following structure:
{ "repo": [ { "name": "resque" }, { "name": "hub" }, { "name": "rip" }, ] }
And then the pattern is defined as follows:
{{#repo}} <b>{{name}}</b> {{/repo}}
But the only difference between this and my data is that I donโt have a โparentโ type of โrepoโ
On the server side, I use the .net library called JSON.net and in the documentation on how collections are serialized:
james.newtonking.com/projects/json/help/html/SerializingCollections.htm
The end result does not include the parent name node, which I do not see in my Mustache template definition:
[ { "Name": "Product 1", "ExpiryDate": "2000-12-29T00:00Z", "Price": 99.95, "Sizes": null }, { "Name": "Product 2", "ExpiryDate": "2009-07-31T00:00Z", "Price": 12.50, "Sizes": null } ]
Is that what I am missing? parent "repo" node from my data so that I can repeat my pattern?
Thank you in advance for your time.
-ed