[英]Failing to replace a document inside a JSONStore collection
我正在開發使用JSONStore和AngularJS的Cordova應用程序(帶有MobileFirst Foundation 8.0)。
以下功能將更新已存儲在本地集合“議程”中的文檔。
update : function(element){
var defer = $.Deferred();
// set query for get document stored in local collection
var query = {id: element.id};
// search for exact value
var options = {
exact: true,
limit: 1
};
var collection = WL.JSONStore.get('agenda');
// invoke search function
collection.find(query, options)//WL.JSONStore.get('agenda').find(query, options)
.then(function (results) {
// handle success - results (array of documents found)
var rowstatus = results[0].json.rowstatus || '';
// substitute current saved document with the update document
results[0].json = element;
// set value of rowstatus flag
results[0].json.rowstatus = rowstatus===''?'UPD':rowstatus;
var arrayMod = [];
arrayMod.push(results[0]);
//invoke replace procedure for update document in local collection
collection.replace(arrayMod, {markDirty: false })//WL.JSONStore.get('agenda').replace(item, {markDirty: false})
.then(function(docsRefreshed){
console.log("docsRefreshed", docsRefreshed);
defer.resolve();
})
.fail(function(refreshErr){
defer.reject(refreshErr);
});
})
.fail(function (findError) {
defer.reject(findError);
});
return defer.promise();
}
這些步驟是:
在本地集合中通過元素的ID查找文檔-IT WORKS
通過替換包含在'json'屬性中的對象來更新文檔的內容:ID不變,我對其進行了驗證-IT WORKS
替換集合中的文檔-IT失敗
返回的錯誤不是失敗處理程序的標准錯誤攔截,它是以下內容:
VM404 worklight.js:5139未捕獲的異常:未捕獲的RangeError:(compiled_code):57__log @ VM404 worklight.js:5139PUBLIC_API。(匿名函數)@ VM404 worklight.js:5539WL.Logger.window.onerror @ VM404超出最大調用堆棧大小worklight.js:5497 VM404 worklight.js:57未捕獲RangeError:超出最大調用堆棧大小(...)it @ VM404 worklight.js:57__handleJsonObj @ VM416 jsonstore.js:1951__handleJsonObj @ VM416 jsonstore.js:1947__handleJsonObj @ VM416 jsonstore.js: 1947__handleJsonObj @ VM416 jsonstore.js:1947__handleJsonObj @ VM416 jsonstore.js:1942__handleJsonObj @ VM416 jsonstore.js:1947__handleJsonObj @ VM416 jsonstore.js:1947__handleJsonObj @ VM416 jsonstore.js:1942__handleJsonObj @ VM416 jsonstore.js:1942 @ VM416 jsonstore.js:1947__handleJsonObj @ VM416 jsonstore.js:1942__handleJsonObj @ VM416 jsonstore.js:1947__handleJsonObj @ VM416 jsonstore.js:1942__handleJsonObj @ VM416 jsonstore.js:1947__handleJsonObj @ VM416 16 jsonstore.js:1942__handleJsonObj @ VM416 jsonstore.js:1947__handleJsonObj @ VM416 jsonstore.js:1942__handleJsonObj @ VM416 jsonstore.js:1947__handleJsonObj @ VM416 jsonstore.js:1942__handleJsonObj @ VM416
來自@ encrico.visentini的評論:
我解決了這個問題。 該錯誤是由從插件自動添加的屬性引起的,該屬性用於導致json對象的循環引用。 刪除此屬性后,我可以替換所有的“ json”對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.