backbone.js - backbone-extend.js doesn't seem to load my method -


i added backbone-extend.js file resides in same folder backbone-min.js...

_.extend(backbone.view.prototype, {     getformdata: function(form) {          var unindexed_array = form.serializearray();         var indexed_array = {};          $.map(unindexed_array, function(n, i){             indexed_array[n['name']] = n['value'];         });          return indexed_array;     } }); 

however, when call this.getformdata in view code, method not defined error. missing? help!

edit: here view. have uncomment getformdata method make work. can't see getformdata otherwise...

define([         'jquery',         'underscore',         'backbone',         'models/member',         'text!templates/memberedittemplate.html'     ], function($, _, backbone, member, memberedittemplate) {      var membereditview = backbone.view.extend({          el: $("#page"),          model: 'member',          initialize: function(args) {             this.member = new member({ id: args.id });             this.member.on('error', this.eventsyncerror, this);             this.member.on('sync', this.eventsyncmodelloaded, this);             this.member.fetch();         },          events: {           "click #bttnmembersave": "bttnclickmembersave"         },          eventsyncerror: function(model,response,options) {             console.log('sync error='+response.statustext);             $('#server-message').css({'color':'red', 'font-weight':'bold'}).text(response.statustext);             //$('#server-message').text(response.statustext);         },          eventsyncmodelloaded: function(model,response,options) {             this.render();         },          eventsyncmodelsaved: function(model,response,options) {             console.log("member saved!");             $('#server-message').css({'color':'green', 'font-weight':'bold'}).text("member saved!");             //$('#server-message').text('member saved!');             var = settimeout(function() { backbone.history.navigate('members', true); }, 2000);         },          bttnclickmembersave: function() {             var data = this.getformdata($('#member-form').find('form'));             this.member.save(data, { success: this.eventsyncmodelsaved });         },          // getformdata: function(form) {          //     var unindexed_array = form.serializearray();         //     var indexed_array = {};          //     $.map(unindexed_array, function(n, i){         //         indexed_array[n['name']] = n['value'];         //     });          //     return indexed_array;         // },          render: function() {             this.member.tojson();             var compiledtemplate = _.template( memberedittemplate, { member: this.member } );             this.$el.html( compiledtemplate );              return this;         }      });      return membereditview;  }); 

ok, added backbone-extend.js requirejs required files array in app.js, it's working.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -