gpt4 book ai didi

sproutcore - 什么是检测 Sproutcore 的window.unload的正确方法

转载 作者:行者123 更新时间:2023-12-03 13:37:57 26 4
gpt4 key购买 nike

我想确保在用户离开页面之前将数据保存在我的 Sproutcore 应用程序中。在Sproutcore中执行此操作的最佳方法是什么?

最佳答案

没有Sproutcore认可的特定方法。但是我做了一些看起来像这样的事情:

在core.js中

MyApp = SC.Object.create({

// ...

storeIsDirty: function(){
var statuses = this.store.statuses, storeKey;
for(storeKey in statuses){
if (statuses[storeKey] & SC.Record.DIRTY) return YES;
}
return NO;
},

storeIsBusy: function(){
var statuses = this.store.statuses, storeKey;
for(storeKey in statuses){
if (statuses[storeKey] & SC.Record.BUSY) return YES;
}
return NO;
}

});

然后在main.js中
window.onbeforeunload = function(){
var dirty = MyApp.storeIsDirty(),
busy = MyApp.storeIsBusy();

if (dirty || busy) {
// User will be prompted with the return value
return 'You have unsaved changes and will lose them if you continue.';
}
}

我知道这是过期的,但希望对您或其他人有帮助。

如果您还有其他问题,请访问#sproutcore上的IRC聊天室,或查看 Sproutcore 列表,电子邮件地址为budemcore@googlegroups.com。

关于sproutcore - 什么是检测 Sproutcore 的window.unload的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3129173/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com