Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从phone gap中的新html中获取id以编辑索引数据库中的数据_Javascript_Html_Phonegap Build_Indexeddb_Phonegap - Fatal编程技术网

Javascript 如何从phone gap中的新html中获取id以编辑索引数据库中的数据

Javascript 如何从phone gap中的新html中获取id以编辑索引数据库中的数据,javascript,html,phonegap-build,indexeddb,phonegap,Javascript,Html,Phonegap Build,Indexeddb,Phonegap,我有一个显示indexedDB列表的页面,然后我想在此页面上编辑它,但我无法获取连接数据的id,请帮助我!! index.html <div id="two"> <form> <input id="filterTable-input" data-type="search"> </form> <table data-role="

我有一个显示indexedDB列表的页面,然后我想在此页面上编辑它,但我无法获取连接数据的id,请帮助我!! index.html

<div id="two">
     <form>
         <input id="filterTable-input" data-type="search">
     </form>
     <table data-role="table" data-filter="true" data-input="#filterTable-input" class="ui-responsive">
         <thead>
             <tr>
                <th>Name</th>
                <th>Type</th>
                <th>Date/Time</th>
                <th>Average meal</th>
                <th>Service</th>
                <th>Cleanliness</th>
                <th>Food quality</th>
                <th>Average Rating</th>
                <th>Reporter</th>
                <th>Note</th>
                <th>Action</th>
              </tr>
          </thead>
          <tbody id="ratingContent" class="ratingContent">

          </tbody>
     </table>
</div>
function refreshTable() {
    var objectStore = db.transaction("rating").objectStore("rating");  
    objectStore.openCursor().onsuccess = function(event) {
       var cursor = event.target.result;      
       if (cursor) {        
          var name = cursor.value.name;
          var type = cursor.value.type;
          var date = cursor.value.date;
          var average = cursor.value.average;
          var service = cursor.value.service;
          var cleanliness = cursor.value.cleanliness;
          var food = cursor.value.food;
          var reporter = cursor.value.reporter;
          var keyPath = cursor.value.id;
          var note = cursor.value.note;
          var rating = cursor.value.ratingAverage;
          var markup = "<tr id='report_"+keyPath+"'><td data-field='name' data-id='"+keyPath+"'><span class='current ratingFeild' contenteditable>" 
            + name + "</span></td><td data-field='type' data-id='"+keyPath+"'><span class='current ratingFeild' contenteditable>" 
            + type + "</span></td><td data-field='date' data-id='"+keyPath+"'><span class='current ratingFeild' contenteditable>" 
            + date + "</span></td><td data-field='average' data-id='"+keyPath+"'><span class='current ratingFeild' contenteditable>" 
            + average  + "</span></td><td data-field='service' data-id='"+keyPath+"'><span class='current ratingFeild' contenteditable>" 
            + service + "</span></td><td data-field='cleanliness' data-id='"+keyPath+"'><span class='current ratingFeild' contenteditable>"
            + cleanliness +"</span></td><td data-field='food' data-id='"+keyPath+"'><span class='current ratingFeild' contenteditable>" 
            + food +"</span></td><td data-field='reporter' data-id='"+keyPath+"'><span class='current ratingFeild' contenteditable>"
            + rating +"</span></td><td data-field='reporter' data-id='"+keyPath+"'><span class='current ratingFeild' contenteditable>"
            + reporter +"</span></td><td data-field='note' data-id='"+keyPath+"'><span class='current ratingFeild' contenteditable>" 
            + note+ "</span></td><td><input type='button' name='record' id='record' value='Delete' onclick='deleteData("+ keyPath +")'></td></tr>";
          $("table tbody").append(markup);
          cursor.continue();//go to next record
       } 
    };
}
$('#ratingContent').on('blur','.ratingFeild',function(){
    var newData = $(this).html();
    var field = $(this).data('field');
    var key = $(this).data('id');
    console.log('hhhh'+ key);
    var transaction = db.transaction(['rating'], "readwrite");
    var store = transaction.objectStore("rating");
    var request= store.get(key);  
    request.onsuccess = function() {
        var data = request.result;
        console.log(data)
        if(field == 'name') {
            data.name = newData;
        } else if(field == 'type'){
            data.type = newData;
        }else if(field == 'date'){
            data.date = newData;
        }else if(field == 'average'){
            data.average = newData;
        }else if(field == 'service'){
            data.service = newData;
        }else if(field == 'cleanliness'){
            data.cleanliness = newData;
        }else if(field == 'food'){
            data.food = newData;
        }else if(field == 'reporter'){
            data.reporter = newData;
        }else if(field == 'note'){
            data.note = newData;
        }

        var requestUpdate = store.put(data);

        requestUpdate.onsuccess = function() {
            alert('Update successfull!');
        }
        requestUpdate.error = function() {
            alert('Error!');
        }
    }
})