Changing mouse cursor while Ember content is saving

谁都会走 提交于 2019-12-13 16:34:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!