Advertisement
Guest User

Untitled

a guest
Jul 31st, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. app.viewExample = Backbone.View.extend({
  2. el: "#in",
  3. template1: _.template( $('#one').html() ),
  4. template2: _.template( $('#two').html() ),
  5.  
  6. events: {
  7. 'click .submit': 'result',
  8. },
  9.  
  10. initialize: function() {
  11. var bool = false;
  12. this.listenTo(app.col, 'all', this.render);
  13. },
  14.  
  15. render: function() {
  16. if (this.bool) {
  17. var rand = Math.floor(Math.random() * app.opts.length);
  18. var value = app.col.at(rand).get("title");
  19. this.$el.html(this.template2( {
  20. result: value
  21. }));
  22. }
  23.  
  24. else if (!this.bool) {
  25. var total = app.col.length;
  26. this.$el.html(this.template1( {
  27. total: total
  28. }));
  29. }
  30. },
  31.  
  32. result: function() {
  33. this.bool = true;
  34. this.render();
  35. }
  36. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement