2014-04-04 88 views
0

我正在使用backbone撤消js为undoredo,我需要检查撤消或重做是否可用。 有像hasundo()hasredo()检查有撤销/重做主干undo

View = Backbone.View.extend({ 
      initialize: function() { 
       // If the model's value changes, update the view 
       this.model.on("change:value", function (model, value, options) { 
        if (value != this.$el.html()) { 
         this.$el.html(value); 
         //need to check here,and add code for enable or disable my undo/redo buttons 

        } 
       }, this); 
      } 
    }) 

回答

1

您需要的,如果属性存在,其类型为“功能”的看到了这个“手动”检查的任何方法。

看到这个答案:Javascript check if function exists

+0

然后你应该做的是在你的模型中写一个'hasUndo'函数,如果'this.model.hasUndo()'为true,则只显示视图中的“撤销”按钮。 –

+0

是的,你需要在你的模型上创建该功能... –

1

有内置到专门为你的使用情况Backbone.Undo.js的isAvailable功能。 Read the documentation here。你只需要编写

如果(myUndoManager.isAvailable( “撤消”)){/ * DoSomething的* /}

由于这个问题是近四个月老,你可能已经在某种程度上解决了这个问题。但是,为了完整性,我仍然想在这里放弃答案。也许它可以帮助其他人扼杀这个线索。 :)