1
questionListViewでレンダリング機能を使用しようとしていますが、実行中ですが、ページを更新していません。バックボーン - ページが更新されないビュー
テンプレート:JSの
<script id="myTemplate" type="text/template">
<p>Test</p>
</script>
パート:
$(function(){
//Test data
var initialListData = [
{ listName: "Sample Questions", listID: 1},
{ listName: "Default questions", listID: 2}
];
// MODELS ----------------------------------------------------
var questionList = Backbone.Model.extend({
defaults: {
listName: "Name of the list",
listID: 0
}
});
// COLLECTIONS ----------------------------------------------------
var populateList = Backbone.Collection.extend({
model: questionList
});
// VIEWS ----------------------------------------------------
var questionListView = Backbone.View.extend({
template: $("#myTemplate").html(),
render: function() {
console.log('I can see this, but nothing happens...');
var tmpl = _.template(this.template);
$(this.el).append(tmpl(this.model.toJSON()));
return this;
}
});
var AppView = Backbone.View.extend({
el : $("#content"),
initialize: function(){
this.collection=new populateList(initialListData);
this.render();
},
render: function(){
_.each(this.collection.models, function (item) {
this.renderSelect(item);
}, this);
},
renderSelect: function(item){
var populateQuestionList = new questionListView({
model: item
});
this.$el.append(populateQuestionList.render().el);
}
});
var app = new AppView();
} (jQuery));
ありがとう!
ありがとうございました!私はチュートリアルのコードの一部をコピーしていて、どのようにトリガされているのかを忘れていました。再度、感謝します! – Matt
問題ありません。それは定型文ですので、簡単に忘れることができます。だからこそ、いつも起こる。そしてちょっと、この答えは6Kの担当者レベルにわたり私を得ました! –