【发布时间】:2011-12-11 05:35:19
【问题描述】:
我的应用程序一切正常,但是当我在浏览器控制台中手动添加对象时,我在 Get 中获取了 json 模型数据,但它没有呈现在网页上。
我在列表视图中调用注释视图以呈现到 UL。
这是我的 html 元素
<html>
<head>
<title> Backbone Demo </title>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<script type="text/template" id="library-template">
<h1> My Notes List </h1>
<ul class="mynotes"></ul>
</script>
<script type="text/template" id="mynote-template">
<div class="mynote-title"> </div>
<div class="mynote-content"</div>
</script>
</head>
<body>
<div id="container">
</div>
</body>
</html>
这是主干视图脚本。
window.LibraryView = Backbone.View.extend({
tagName: 'section',
className: 'mynotes',
initialize: function() {
_.bindAll(this, 'render');
this.template = _.template($('#library-template').html());
this.collection.bind('reset', this.render);
},
render: function() {
var $mynotes,
collection = this.collection;
$(this.el).html(this.template({}));
$mynotes = this.$(".mynotes");
collection.each(function(mynote) {
var view = new LibraryMynoteview({
model: mynote,
collection: collection
});
$mynotes.append(view.render().edl);
});
return this;
}
});
【问题讨论】:
-
你能显示你的内容的格式吗?你的 json 数据是什么样子的?
标签: javascript ruby-on-rails json backbone.js