English 中文(简体)
执行
原标题:Implementing undo

I m 绘制地图编辑网络应用程序,使我们能够建立和编辑多线、多角等。 我在网上找不到一些关于无所作为的信息,我发现有人对“我们的需要不成事实”和“在我指挥模式使用关闭的情况下”,但我想到的是,这同一个完全的无所事事的/充满活力的界面之间有相当的路。

因此,我的问题是我的问题(我相信,我的好人选):

  • Should I manage the stack, or is there a way to send my commands to the browser s stack ? (and how do I handle native commands, like text edits in textifields in this case)
  • how do I handle "command compression" (command grouping) when some commands are browser native
  • How do I detect the undo (ctrl+z) keystroke?
  • If I register a keyup event, how do I decide if I prevent default or not?
  • If not, can I register some undoevent handler somewhere ?
  • Users are not used to undo on the web, how can I "train" them to explore/undo on my application ?
问题回答

您需要具备制造和删除物体的职能。 然后将这些职能转嫁给单人经理。 See the demo file of my javascript undo Manager: https://github.com/ArthurClemens/Javascript-Undo-Manager

《血清法》显示了血管,但该法典是空洞的。

它含有关键的约束力,但可以帮助您采取初步步骤。

我 我已在与纽埃和雷多州一起在网络应用中利用了这一信息,随后可以节省费用。

这里是使用Knockout JS的N-level undo样本:

(function() {
    
    //current state would probably come from the server, hard coded here for example
    var currentState = JSON.stringify({
        firstName:  Paul ,
        lastName:  Tyng ,
        text:  Text  
    })
       , undoStack = [] //this represents all the previous states of the data in JSON format
        , performingUndo = false //flag indicating in the middle of an undo, to skip pushing to undoStack when resetting properties
        , viewModel = ko.mapping.fromJSON(currentState); //enriching of state with observables
        
    
    //this creates a dependent observable subscribed to all observables 
    //in the view (toJS is just a shorthand to traverse all the properties)
    //the dependent observable is then subscribed to for pushing state history
    ko.dependentObservable(function() {
        ko.toJS(viewModel); //subscribe to all properties    
    }, viewModel).subscribe(function() {
        if(!performingUndo) {
        undoStack.push(currentState);
        currentState = ko.mapping.toJSON(viewModel);
    }
    });
        
    //pops state history from undoStack, if its the first entry, just retrieve it
        window.undo = function() {
            performingUndo = true;
            if(undoStack.length > 1)
            {
                currentState = undoStack.pop();
                ko.mapping.fromJSON(currentState, {}, viewModel);
            }
            else {
                currentState = undoStack[0];
                ko.mapping.fromJSON(undoStack[0], {}, viewModel);
            }
            performingUndo = false;
    };
    
    ko.applyBindings(viewModel);
})();
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/1.2.1/knockout-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>
<div>
    <button data-bind="click: function() { undo(); }">Undo</button>
    <input data-bind="value: firstName" />
    <input data-bind="value: lastName" />
    <textarea data-bind="value: text"></textarea>
</div>

它使用MVVER模型,因此,贵国的页数以它保存历史的 j印标语表示。

Cappuccino自动支持工作的方式是向单人管理人说明哪些财产应当无法使用。 例如,在你管理学生记录时,你可以做以下事情:

[theUndoManager observeChangesForKeyPath:@"firstName" ofObject:theStudent];
[theUndoManager observeChangesForKeyPath:@"lastName" ofObject:theStudent];

现在,无论学生名称如何在教育、青年和体育部中发生变化,打上 un子将自动恢复。 简明扼要还自动处理同一跑道的合并变化,将文件标记为“dirty”(“need Save”),而有些项目属于“unty”,等等(换言之,上述内容应当是为了支持undo。

另一个例子是,如果你想要增加和删除学生,那么你就是:

[theUndoManager observeChangesForKeyPath:@"students" ofObject:theClass];

由于“学生”是各环礁岛的一系列学生,因此将跟踪这些阵列的增减情况。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签