Chrome 应用程序的 PouchDB

PouchDB for Chrome Apps

我正在制作一个 Chrome 应用程序并使用 PouchDB(这是我的第一次)。在 DevTools 的资源面板上获得了 IndexedDB 运行。问题是向 PouchDB 添加和更新数据。没用。

代码如下:(app_jr.js)

var saveregister, JrRegisterObj, pn;

JrRegisterObj = function (databasename, remoteorigin){
'use strict';

Object.defineProperty(this, 'pdb', {writable:true});
Object.defineProperty(this, 'remote', {writable:true});
Object.defineProperty(this, 'formobject', {writable:true});
Object.defineProperty(this, 'errordialog', {writable: true});

this.pdb = new PouchDB(databasename);
this.remote = remoteorigin + '/'+databasename;

};

saveregister = function(event) {
var n = {};

if(!this.formobject._id.value){
    n._id = new Date().getTime() + '';
} else {
    n._id = this.formobject._id.value;
}

n.jr_u_ubn = (this.formobject.jr_u_ubn.value === '') ? '' :    this.formobject.jr_u_ubn.value;
n.jr_u_name = (this.formobject.jr_u_name.value === '') ? '' : this.formobject.jr_u_name.value;
n.jr_u_branch = (this.formobject.jr_u_branch.value === '') ? '' : this.formobject.jr_u_branch.value;

this.pdb.put(n, function(error, response){
    if(error){
        console.log(error);
        return;
    } else if(response && response.ok){

    }
});
}

pn = new JrRegisterObj('jr_register');

pn.formobject = document.getElementById('jr_reg_form');
pn.errordialog  = document.getElementById('errordialog');

pn.formobject.addEventListener('submit', function (e){
e.preventDefault();
pn.saveregister();
});

对于 html 文件:(junior-register.html)

<!DOCTYPE html>
<html lang="en-us" manifest="jr_register.manifest">
<head>
<title>Junior Registration</title>
<link rel="stylesheet" href="css/style.css">

</head>

<body>
<div class="header">
  <h1>Junior Register</h1>
</div>
<section id = "add_jr">
<form class="pure-form" id = "jr_reg_form" method="post">
  <fieldset>
    <legend>Register</legend>
    <table align="center">
      <tr>
        <input type="hidden" id="_rev" name="_rev" value="">
        <input type="hidden" id="_id"  name="_id" value="">
        <td>UBN:</td>
        <td><input type="text" id="jr_u_ubn" name_u="jr_u_ubn"></td>
      </tr>
      <tr>
        <td>Name:</td>
        <td><input type="text" id="jr_u_name" name="jr_u_name"></td>
      </tr>
      <tr>
        <td>Branch:</td>
        <td><input type="text" id="jr_u_branch" name="jr_u_branch"></td>
      </tr>
    </table>
    <button type="submit" id="jr_register_btn" class="pure-button pure-button-primary">Register</button>
  </fieldset>
</form>
</section>

<script type="text/javascript" src="js/app_jr.js"></script>
<script type="text/javascript" src="js/pouchdb-nightly.min.js"></script>
<script type="text/javascript" src="js/pouchdb.mapreduce.noeval.js">   </script>
<script type="text/javascript" src="js/jr-register.js"></script>
</body>
</html>

我得到了here

的帮助

我真的很努力地研究这个,但我找不到解决办法。非常感谢你的帮助。

嗯,我回答了我自己的问题..(app.js)

var pdb = new PouchDB('pouchjrreg');

var form, savenote;

form = document.getElementById('jrregform');

savenote = function(event){
var o ={};

o.jr_u_ubn = form.jr_u_ubn.value;
o.jr_u_name = form.jr_u_name.value;
o.jr_u_branch = form.jr_u_branch.value;

if(event.target._id.value == ''){
o._id = new Date().getTime() + '';
} else {
o._id = event.target._id.value;
}

pdb.put(o, function(error, response){
if(error) {
  console.log(error);
  return;
} else if(response && response.ok){

}
});
}

form.addEventListener('submit', savenote);

现在可以使用了! html 文件的一些更新。