javascript - Calling prototype method from another method -
i trying call prototype method jquery event handler. have code this:
$('#' + this.id + ' .selmake').on('change', this.getcarmodel()); i error saying: uncaught typeerror: object [object global] has no method 'getcarmodel'
what doing wrong here?
use code:
vehicleselect.prototype.getcarmakes = function() { // optional parameters var options = {}; var select = $('#' + this.id + ' .selmake'), = this; select.on('change', function(e) { that.getcarmodel(); }); // callback function called when api response returned function success(res) { (var i=0; i<res.makes.length; i++) { $("<option>",{ value: res.makes[i].nicename, html: res.makes[i].name }).appendto(select); } select.removeattr("disabled"); select + $(' option[value="placeholder"]').html('select make'); } // oops, have problem! function fail(data) { console.log(data); } // fire api call this.res.api('/api/vehicle/v2/makes', options, success, fail); }; for why can't use select.on('change', this.getcarmodel) see this question (which provides alternative solutions).
Comments
Post a Comment