[英]Remove all documents in a JSONStore collection (without using removeCollection() )
我正在研究IBM Worklight,並且對JSONStore有疑問。 我如何編寫一個函數來刪除JSONStore集合中的所有文檔,並保留該集合的引用?
換句話說,我想刪除文檔而不刪除集合。 我無法在應用程序中使用removeCollection(),因為無法退出應用程序並再次調用wlCommonInit()(在JSONStore上調用get和init)。
非常感謝您的幫助Andrea
目前,沒有API可以輕松實現這一目標。 您的選擇是:
1.調用remove collection然后初始化要清除並重新使用的特定集合。 無需再次調用wlCommonInit
。 一些偽代碼:
var collections = {
people : {...},
orders: {...},
greetings: {...}
};
var options = {...};
WL.JSONStore.get('greetings').removeCollection()
.then(function () {
return WL.JSONStore.init({greetings: collections.greetings}, options);
})
.then(function () {
//re-use the collection here
});
2.使用find
API查找文檔,並使用remove
API刪除文檔。 這里有一個例子 。
您可以在此處打開功能請求。
假設訪問權限是您集合的訪問者,則可以執行以下操作:
access.findAll()
.then(function(result){
if(result.length>0)
{
access.remove(result,{push:false})
}
})
.fail(function(error_msg){
alert(error_msg);
});
但請記住,這不會重置ID(愚蠢的jsonstore!),因此每次您執行操作時,它們都會偏移集合的長度。
PS:根據我的經驗,在加密集合的情況下應該避免使用removeCollection API,因為在低性能的移動設備上初始化加密集合會花費時間。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.