javascript - Backbone.js manually trigger "error" on a collection -
If my server / jsn returns a specific status (for example no results) then i I want to fail
Problem: The default error-handler is not called (since the collection successfully receives Jason. So my idea is to use a pars function to see an error code in JSS
But how do I trigger the error-method and inform my idea (and stop trying to create the model)
/ * Global Defined * / Defined (['underscore', 'backbone', 'model / miam '', Use 'strict use'; var SomeCollection = Backbone.collection.extend ({Model: MyModel, value: null, url: function () {Return url: "data / list" .json ";}, initialize: function (model, option) {this.zipcode = options.zipcode;}, pars: function (feedback, xhr) {if (response.status = =" OK ") {Console.info ( "Status:" + response.status; return response. Results;} Else {console.warn ("status:" + response.status + - message: "+ response.message); This.trigger ('failed') / / Return response does not work;}}}); some collection returns;});
< P> in Area near a post on my blog about things like this, unfortunately it is in Portuguese, but that Google Translate helps.
I have to handle this way
GetSomething: - & gt; @result = @fetch (success: () = & gt; @trigger "succesthing1" if @rot. Status 204 @ tringer "success typing 2" if @rots.gets 200 error: () => @trager "error "
Now I can hear these triggers to see and can take correct action from the server for a particular result
Comments
Post a Comment