0
我正在構建應用程序來存儲信息項目。目前有3個輸入字段(標題,說明和文件輸入)。PouchDB代碼在添加附件時不起作用
當我填寫所有三個字段並調用addItem()函數時,它的工作原理。但是,當我將輸入字段留空時,該函數不會將其添加到數據庫中。
有沒有辦法告訴文件輸入字段不是必需的?
我的javascript代碼:
function addItem() {
//get file
var inputFile = document.querySelector('#inputFile');
var getFile = inputFile.files[0];
//get info
var title = document.getElementById('itemTitle').value;
var desc = document.getElementById('itemDesc').value;
//add
locallp.put({
_id: new Date().toISOString(),
title: title,
description: desc,
_attachments: {
"file": {
content_type: getFile.type,
data: getFile
}
}
}).then(function(){
console.log("Added to the database");
location.href = "menu.html";
}).catch(function(err){
console.log(err);
});
}
一些額外的信息,我使用的科爾多瓦構建應用程序。我的數據庫是PouchDB,並通過couchperuser連接到CouchDB服務器。
謝謝。只是好奇,如果有袋內的選項或東西。我會嘗試使用兩個不同的put()函數。 – thomagron
這與PouchDB無關,像'getFile.type'這樣的代碼在'getFile'爲'null'時根本無法工作。 – smathy