0

I'm trying to get icanhaz/mustache loop working, as defined in this answer and I'm getting following error in browser console:

Uncaught Error: Syntax error, unrecognized expression: <option value="1">First</option>
                        <option value="2">Second</option>

Don't know why. I've just managed to spot that this is the line that causes the problem:

ich.myTemplate(listOfStuff);

This is my entire code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/tr/html4/transitional.dtd">
<html>
    <head>
        <title>icanhaz.js demo</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
        <script type="text/javascript" src="https://raw.github.com/HenrikJoreteg/ICanHaz.js/master/ICanHaz.js"></script>
    </head>
    <body>

    <select id="mySelectBox">
    </select>

    <script id="myTemplate" type="text/html">
        {{#stuff}}
        <option value="{{key}}">{{desc}}</option>
        {{/stuff}}
    </script>

    <script>
        $(document).ready( function() {

            var listOfStuff = {stuff: [ 
                    {key: "1", desc: "First"},
                    {key: "2", desc: "Second"}
                ]};
            var x = ich.myTemplate(listOfStuff);
            $("#mySelectBox").append(x);
        });
    </script>

</body>
</html>

Thanks for any suggestions!

Community
  • 1
  • 1
ducin
  • 25,621
  • 41
  • 157
  • 256

2 Answers2

2

Finally I found the error. It was the jquery version problem - 1.9.1 was returning the error and 1.8.3 was not. Compare those demos:

for the 1.9.1 version, look at the javascript console.

Moreover, if I changed

<script id="myTemplate" type="text/html">
    {{#stuff}}
    <option value="{{key}}">{{desc}}</option>
    {{/stuff}}
</script>

to

<script id="myTemplate" type="text/html">
    {{#stuff}}<option value="{{key}}">{{desc}}</option>{{/stuff}}
</script>

for 1.9.1, it also worked fine.


edit: this is an opened issue on icanhaz/github. If you wish, please help to fix this bug!

ducin
  • 25,621
  • 41
  • 157
  • 256
0
var listOfStuff = {stuff: [ 
                  {key: "1", desc: "First"},
                  {key: "2", desc: "Second"}
              ]};
var html = ich.myTemplate(listOfStuff);
$("#mySelectBox").append($(html));

Try that?

calumbrodie
  • 4,722
  • 5
  • 35
  • 63
  • I've provided all the code I'm executing. It is 100% the same as in mentioned example and it returns mentioned error. I don't know why. – ducin Mar 27 '13 at 17:01
  • so what happens id you use the dollar syntax to wrap your html before you append it? – calumbrodie Mar 27 '13 at 21:43
  • Please look at my answer below. Look at those links and run them in your browser. Can you tell me which jquery version are you using with above code? – ducin Mar 27 '13 at 21:53