Skip to content

Commit 4d2ce08

Browse files
committed
needed to reset medalist arrays
1 parent 3c2636d commit 4d2ce08

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

examples/modular-backbone/js/router.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ define([
99
'views/footer/FooterView'
1010
], function($, _, Backbone, HomeView, ProjectsView, ContributorsView, FooterView) {
1111

12-
var contributorsView;
13-
1412
var AppRouter = Backbone.Router.extend({
1513
routes: {
1614
// Define some URL routes
@@ -36,15 +34,9 @@ define([
3634

3735
app_router.on('route:showContributors', function () {
3836

39-
// there is a problem here -- when it draws the first everything is fine
40-
// but when it returns to this view, it adds the items to the list again
41-
// even though the collection has the same number of models
42-
// why won't it empty the divs?! I can do it in the console...
43-
if ( String(contributorsView) !== "undefined" ) contributorsView.clearListView();
44-
4537
// Like above, call render but know that this view has nested sub views which
4638
// handle loading and displaying data from the GitHub API
47-
contributorsView = new ContributorsView();
39+
var contributorsView = new ContributorsView();
4840
});
4941

5042
app_router.on('route:defaultAction', function (actions) {

examples/modular-backbone/js/views/contributors/ContributorsListView.js

+23-15
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,17 @@ define([
2323

2424
clearListView : function(){
2525

26+
var that = this;
27+
2628
console.log("clearing sub sub view");
2729

2830
$("#gold-podium").empty();
2931
$("#silver-podium").empty();
3032
$("#bronze-podium").empty();
33+
34+
that.goldContributors = [];
35+
that.silverContributors = [];
36+
that.bronzeContributors = [];
3137

3238
},
3339

@@ -65,30 +71,32 @@ define([
6571
achievement: '1 - 5 Contributions'
6672
}
6773

68-
6974
var data = {
7075
contributors: that.goldContributors,
7176
_: _,
7277
podium : goldPodium
73-
};
78+
};
79+
80+
// render bronze list
81+
data.contributors = that.bronzeContributors;
82+
data.podium = bronzePodium;
83+
84+
var bronzeCompiledTemplate = _.template( contributorListTemplate, data );
85+
$("#bronze-podium").html( bronzeCompiledTemplate );
7486

75-
// render gold list
76-
data.contributors = that.goldContributors;
77-
data.podium = goldPodium;
78-
var compiledTemplate = _.template( contributorListTemplate, data );
79-
$("#gold-podium").html( compiledTemplate );
80-
8187
// render silver list
8288
data.contributors = that.silverContributors;
8389
data.podium = silverPodium;
84-
var compiledTemplate = _.template( contributorListTemplate, data );
85-
$("#silver-podium").html( compiledTemplate );
8690

87-
// render bronze list
88-
data.contributors = that.bronzeContributors;
89-
data.podium = bronzePodium;
90-
var compiledTemplate = _.template( contributorListTemplate, data );
91-
$("#bronze-podium").html( compiledTemplate );
91+
var silverCompiledTemplate = _.template( contributorListTemplate, data );
92+
93+
$("#silver-podium").html( silverCompiledTemplate );
94+
95+
// render gold list
96+
data.contributors = that.goldContributors;
97+
data.podium = goldPodium;
98+
var goldCompiledTemplate = _.template( contributorListTemplate, data );
99+
$("#gold-podium").html( goldCompiledTemplate );
92100

93101
that.animate();
94102

examples/modular-backbone/js/views/contributors/ContributorsView.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ define([
44
'backbone',
55
'collections/contributors/ContributorsCollection',
66
'views/contributors/ContributorsListView',
7+
'events/contributors/ContributorsEvent',
78
'text!templates/contributors/contributorsTemplate.html'
8-
], function($, _, Backbone, ContributorsCollection, ContributorsListView, contributorsTemplate){
9+
], function($, _, Backbone, ContributorsCollection, ContributorsListView, ContributorsEvent, contributorsTemplate){
910

10-
var contributorsListView;
11+
//var contributorsListView;
1112

1213
var ContributorsView = Backbone.View.extend({
1314

@@ -21,15 +22,16 @@ define([
2122
that.render();
2223
}
2324

24-
this.collection = new ContributorsCollection([]);
25-
this.collection.fetch({ success : onDataHandler, dataType: "jsonp" });
26-
25+
that.collection = new ContributorsCollection([]);
26+
that.collection.fetch({ success : onDataHandler, dataType: "jsonp" });
27+
2728
},
2829

2930
render: function(){
3031

3132
$('.menu li').removeClass('active');
3233
$('.menu li a[href="'+window.location.hash+'"]').parent().addClass('active');
34+
3335
var total_contributions = this.getTotalContributions(this.collection.models);
3436
var total_contributors = this.collection.models.length;
3537

@@ -41,7 +43,7 @@ define([
4143
this.$el.html( compiledTemplate );
4244

4345
// sub view
44-
contributorsListView = new ContributorsListView({ collection: this.collection});
46+
var contributorsListView = new ContributorsListView({ collection: this.collection});
4547
contributorsListView.render();
4648

4749
},

0 commit comments

Comments
 (0)