【发布时间】:2015-05-23 17:22:46
【问题描述】:
我在尝试在 pouch db 中插入数据时遇到错误。 我通过在 youtube 上看到你的视频来执行基本的 crud 操作。 但是在检索表时出现此错误
未捕获的类型错误:db.alldocs 不是函数
我是单页应用程序的新手。
这是我的代码
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>APP</title>
<script src="//cdn.jsdelivr.net/pouchdb/3.5.0/pouchdb.min.js"></script>
<script>
var db = new PouchDB('courts');
function searchCase(){
var caseno = window.document.courtform.caseno.value;
var casetype = window.document.courtform.casetype.value;
var year = window.document.courtform.year.value;
var store={
_id: caseno,
type: casetype,
yr: year
};
db.put(store, function callback(error,result)
{
if(!error){
clearfields();
document.getElementById("message").innerHTML=
"succesfully added";
}
alert("success");
});
}
function showCase(){
db.alldocs({include_docs: true, descending: true},
function(err,doc){
showTableofCases(doc.rows);
} );
function showTableofCases(data){
var div = document.getElementById("message");
var str="<table border='1' align= 'center'><tr><th>xxx</th>"+
"<th>vvv</th><th>hhh</th></tr>";
for(var i=0;i<data.length;i++){
str+= "<tr><td>"+data[i].doc._id+
"</td><td>"+data[i].doc.type+
"</td><td>"+data[i].doc.year+"</td></tr>";
}
str+="</table>";
div.innerHTML = str;
}
}
function clearfields(){
window.document.courtform.caseno.value="";
window.document.courtform.casetype.value="";
window.document.courtform.year.value="";
}
</script>
</head>
<body>
<form name="courtform">
<div align="center">
Case No<br/><input type="text" name="caseno" /><br/><br/>
Case Type
<select id="casetype" name="casetype" >
<option value="1" selected>WA</option><option value="2">WP</option><option value="3">SA</option><option value="4">AS</option></select><br/><br/>
Case Year<select id="year" name="year" >
<option value="0">2015</option>
<option value="1">2016</option>
</select><br/><br/>
<input type="button" value="Save" onclick="searchCase()" />
<input type="button" value="show" onclick="showCase()" />
<input type="button" value="Clear" onclick="clearfields()"/>
</div> </form>
<div id="message"></div>
</body>
</html>
告诉我 igoi 哪里错了??? Morover 我很高兴创造这项新技术的人回答了我的问题....那是 gr8!!!! 提前谢谢!!!!
【问题讨论】:
-
如果您正确地标记和标题,您将获得更多帮助。 PouchDB 不是 HTML5 本地存储,与 HTML 无关。它是一个开源的 JavaScript 数据库,StackOverflow 有它自己的标签。所以把PouchDB放在你的标题里,把tag改成PouchDB,你可能会得到一些答案。
标签: pouchdb