2017-04-06 48 views
0

這是我一直在努力的代碼。由於某種原因,它返回給我以下錯誤:PouchDB更新文檔:DataCloneError

Uncaught DataCloneError: Failed to execute 'put' on 'IDBObjectStore': An object could not be cloned. 

甚至在我嘗試使用upsert插件之前就發生了這種情況。

db.get(id).then(doc => { 
    console.log(doc); 
    return db.upsert(id, doc => { 
     doc.exp_date = moment(doc.exp_date).add(parseInt(document.getElementById('ext_date').value), 'years'); 
     return doc; 
    }).then(res => console.log(res)).catch(err => console.log(err)); 
}) 

我可以知道這個錯誤的分辨率嗎?

回答

1

瞬間實例無法克隆。嘗試:

postMessage(moment(0), '*'); // also throws DataCloneError DOMException 

logic for cloning不允許複製功能,可能是這種情況。比較:

postMessage({f: function(){}}); // also throws DataCloneError 

並檢查:

typeof moment(0)._locale.ordinal; // "function" 

你需要,

+0

通過add()返回的東西,可以被克隆,如日期,數量等對象轉換我採取了一些不同的方式解決了這個問題。我在PouchDB問題上得到了答案。我簡單地使用了'moment(...)。add(...)._ d' –