我正在尝试将内容加载到页面而不向我收费,可能是视图问题,因为如果我工作,模型会获得数据。骨干js不太了解,我正在寻找使用JSON示例在网站上显示内容。
请问你能帮帮我吗?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.com/backbone/backbone-min.js"></script>
<script>
$(function() {
var Article = Backbone.Model.extend();
var ArticleList = Backbone.Collection.extend({
model: Article,
url: 'https://support.mozilla.org/en/search?topics=hot&a=1&w=1&format=json&callback=?',
parse: function(response) {
return response.results;
}
});
var articleView = Backbone.View.extend({
initialize: function(){
this.render();
},
render: function(){
var tmpl = _.template( $("#articleTemplate").html(), {} );
var html = template.tmpl(this.model.toJSON());
this.$el.html( html );
}
});
var articles = new ArticleList();
var articlesView = new articleView({model: articles});
articles.fetch();
articles.bind('reset', function() {
articlesView.render();
});
});
</script>
<title>Fortified Studio</title>
</head>
<body>
<div id="articles"></div>
<script id="articleTemplate" type="text/template">
<div class="results">
<div class="search_summary">
<%= search_summary %>
</div>
</div>
</script>
</body>