0

I'm using HTML, JavaScript, and jQuery Mobile to make a kind of picture gallery. I'm following the JQM demo at: http://jquerymobile.com/demos/1.3.0-beta.1/docs/demos/swipe/swipe-page.html to make the gallery, but it uses a totally different HTML page for each picture. My plan is for the gallery to be dynamic, so I don't have a set number of pages or a set list of picture names, etc, and I thought I might use Mustache to make a picture template, and create the pages dynamically. Here is the basic layout of the code:

In index.html

<!DOCTYPE html>

<html>
<head>
    ...
    <script src="mustache-0.7.0-min.js" type="text/javascript"></script>
    <script src="mobile.js" type="text/javascript"></script>
    <script id="test_template" type="text/html">
        <h1>{{firstName}} {{lastName}}</h1>
        <p>{{tempText}}</p>
    </script>
    ...
</head>
...

And then in mobile.js

function showPerson()

{


    var person = 
        {
            firstName: "Feaf",
            lastName:  "McFeaf",
            tempText:  "Hello Feaf"
        };

    var personTemplate = document.getElementById("test_template").innerHTML;

    var html = Mustache.to_html(x, person);

}

So it's about as basic as you can get. However, when I run the web app on a local server (in Chrome), and I step through this function, I get an error at the Mustache.to_html line, saying

Uncaught TypeError: Cannot call method 'to_html' of undefined

I'm fairly new to web development, and brand new to Mustache, so I do not know what could be causing this error. I've tried calling other Mustache methods, like render, but the same error appears. Is the <script src=...> not enough to have the Mustache library accessible to mobile.js? Anybody have any tips on what I might be doing wrong?

Thank you for any information, and let me know of any other information I should add.

EDIT:

Whoops! Forgot to include the fact that I had mustache in the scripts section, I've edited to reflect this fact. Just to be clear, I DO have (and always have had) mustache included!

Also, I tried the suggestion of @Zorayr of using console.log(Mustache), and it claims that Mustache is undefined, even though I am importing it as noted above. Why might this be?

4

1 回答 1

0

作为问题的解决方案,我最终下载并使用了 Handlebars。在我看来,与项目中已经存在的 Mustache 库和我添加的新库存在一些冲突。这并不能真正解释为什么 Mustache 会未定义,但这是我的解决方法。

于 2013-08-13T18:07:57.683 回答