1

js 应用程序没有显示它应该显示的内容。

这是应用程序:http: //jsfiddle.net/5sded/

它应该循环浏览食谱,但它没有显示任何内容。这是html:

<div id="recipes">
        <div class="recipeContainer">
            <img src="img/placeholder.png"/>
            <ul>
                <li>Name</li>
            </ul>
        </div>
        <script id="recipeTemplate" type="text/template">
            <img src="<%= image %>"/>
            <ul>
                <li><%= name %></li>
            </ul>
        </script>
</div>

也没有任何错误弹出。

4

1 回答 1

2

2 你的代码有问题..

首先对. backbone_ _underscore

加载库的顺序很重要

---> Underscore

---> Backbone

看起来你是先加载主干。

检查小提琴

第二个问题是你的模板中有这个 <%= image %>

其中 asimage属性在默认属性的对象数组中也不可用。

将其替换为<%= url %> 。那应该使代码正常工作。

此外,我更喜欢在初始化视图时传递集合。不过,这与错误无关。

var recipesView = new RecipesView({
    collection : new Recipes(recipes)
});
于 2013-07-23T02:20:07.250 回答