Fixed view state issues where collections aren't rendered when updated

This commit is contained in:
Björn Dahlgren 2015-04-17 19:56:47 +02:00
parent 4130006650
commit 594487a60e
4 changed files with 18 additions and 13 deletions

View File

@ -20,11 +20,7 @@ define(function (require) {
missions = new Missions(),
mods = new Mods(),
servers = new Servers(),
layoutView = new LayoutView({el: $body}).render(),
navigationView = new NavigationView({servers: servers}),
serversView = new ServersView({collection: servers}),
missionsView = new MissionsView({missions: missions}),
modsListView = new ModsListView({collection: mods});
layoutView = new LayoutView({el: $body}).render();
return Backbone.Router.extend({
@ -37,7 +33,7 @@ define(function (require) {
},
initialize: function () {
layoutView.navigation.show(navigationView);
layoutView.navigation.show(new NavigationView({servers: servers}));
missions.fetch();
var socket = io.connect();
@ -50,8 +46,7 @@ define(function (require) {
},
home: function () {
layoutView.content.show(serversView);
serversView.delegateEvents();
layoutView.content.show(new ServersView({collection: servers}));
},
logs: function () {
@ -61,13 +56,11 @@ define(function (require) {
},
missions: function () {
layoutView.content.show(missionsView);
missionsView.delegateEvents();
layoutView.content.show(new MissionsView({missions: missions}));
},
mods: function () {
layoutView.content.show(modsListView);
modsListView.delegateEvents();
layoutView.content.show(new ModsListView({collection: mods}));
},
server: function (id) {
@ -75,7 +68,7 @@ define(function (require) {
if (server) {
layoutView.content.show(new ServerView({model: server, mods: mods}));
} else {
this.navigate("#", true)
this.navigate("#", true);
}
}

View File

@ -15,5 +15,9 @@ define(function (require) {
itemView: ListItemView,
itemViewContainer: "tbody",
template: template,
initialize: function (options) {
this.listenTo(this.collection, "change reset", this.render);
},
});
});

View File

@ -21,6 +21,10 @@ define(function (require) {
"click #download": "download"
},
initialize: function (options) {
this.listenTo(this.collection, "change reset", this.render);
},
download: function (event) {
event.preventDefault();
var view = new FormView({mods: this.collection});

View File

@ -25,6 +25,10 @@ define(function (require) {
"click #add-server": "addServer"
},
initialize: function (options) {
this.listenTo(this.collection, "change reset", this.render);
},
buildItemView: function(item, ItemViewType, itemViewOptions){
// build the final list of options for the item view type
var options = _.extend({model: item}, itemViewOptions);