0
alert()
을 render
의 내부에서 사용하면 UserListView
의 출력이 올바르게 표시됩니다. 내가 alert()
라고 말하면,보기는 표시되지 않습니다.보기가 올바르게 표시되지 않습니다.
저는 여기에 붙어 있습니다. 왜 그런가요?
var User = Backbone.Model.extend({
defaults: {}
});
var UserCollection = Backbone.Collection.extend({
model: User,
url: 'http://localhost/cirest/index.php/api/userapi/users'
});
var UserView = Backbone.View.extend({
tagName: 'thumbnail',
className: 'span12',
template: $('#userdetailtemplate').html(),
render: function() {
var tmpl = _.template(this.template);
this.$el.html(tmpl(this.model.toJSON()));
return this;
}
});
var UserListView = Backbone.View.extend({
el: ('#content1'),
initialize: function() {
this.collection = new UserCollection();
this.collection.fetch();
this.render();
},
render: function() {
var that = this;
alert('asdf');
_.each(this.collection.models, function (item) {
that.renderUser(item);
}, this);
},
renderUser: function (item) {
var userview = new UserView({
model: item
});
this.$el.append(userview.render().el);
}
});
$(function() {
var uview = new UserListView();
});
html로 페이지 : : 여기
코드입니다<div id="content1" class="span12"></div>
<script type="text/template" id="userdetailtemplate">
<%= user_name %> <%= user_email %>
</script>
이와 비슷한 것 http://stackoverflow.com/questions/8413500/backbone-js-populating-a-collection/8415515#8415515? – nikoshr
안녕하세요 @nikoshr 의견을 보내 주셔서 고맙습니다. –