Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.viewExample = Backbone.View.extend({
- el: "#in",
- template1: _.template( $('#one').html() ),
- template2: _.template( $('#two').html() ),
- events: {
- 'click .submit': 'result',
- },
- initialize: function() {
- var bool = false;
- this.listenTo(app.col, 'all', this.render);
- },
- render: function() {
- if (this.bool) {
- var rand = Math.floor(Math.random() * app.opts.length);
- var value = app.col.at(rand).get("title");
- this.$el.html(this.template2( {
- result: value
- }));
- }
- else if (!this.bool) {
- var total = app.col.length;
- this.$el.html(this.template1( {
- total: total
- }));
- }
- },
- result: function() {
- this.bool = true;
- this.render();
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement