问题
I know Ember makes it quite straight forward to display an indicator on route transitions that take a long time.
But what's the easiest way to do the same after a Save button is clicked, and until the save operation completes? I am not finding much on this.
回答1:
Assuming based off the tag you are using ember data
$('html,body').css('cursor','crosshair');
record.save().finally(function(){
// revert mouse
});
http://emberjs.com/api/classes/Ember.RSVP.Promise.html#method_finally
Obviously this is limited, and crosshair, but it shows the general idea, and typing in a phone sucks, I apologize.
回答2:
Thanks to kingpin2k, I feel this solution pretty nicely handles EmberData Model ajax operations:
DS.Model.reopen
save: ->
@cursorWait()
@_super().finally =>
@cursorDefault()
createRecord: (hash) ->
@cursorWait()
@_super(hash).finally =>
@cursorDefault()
destroyRecord: ->
@cursorWait()
@_super().finally =>
@cursorDefault()
cursorWait: ->
$('html,body').css('cursor', 'wait')
cursorDefault: ->
$('html,body').css('cursor', 'default')
And one can still chain a finally and/or a then while calling the model methods:
actions:
save: ->
@controller.content.save().then(-> console.log 'then').finally(-> console.log 'another finally')
来源:https://stackoverflow.com/questions/24332998/changing-mouse-cursor-while-ember-content-is-saving