SQLite는 오프라인 DB : 나는 아케이드 기계에 돈을 기록하는 간단한 DB를 생성하는 데 사용하고 http://www.mobilehtml5.com/post/401111526/tutorial-your-first-mobile-html5-app-offline-storageHTML 5 나는이 튜토리얼을 통해 일한지
이름과 양을 저장하는 테이블, 각 기계에서.
제 문제는 행을 쉽게 편집 할 수있는 가장 좋은 방법이 없다는 것입니다. html5rocks.com은 나에게 몇 가지 아이디어를 주었지만 적절한 것은 아니 었습니다.
아무도 나를 제대로 궤도에 올려 놓을 수 있습니까? 나는 올바른 접근법을 모르지만, 이것을 수행하는 커서 유형의 일종이 있습니까? 또는 입력 양식 상자에 값을로드하고 이러한 업데이트하려면 루프가 있어야합니까?
도움이 될만한 의견이 있으시면 아래 코드를 포함 시켜서 내가하는 일을 볼 수 있습니다.
<!DOCTYPE html>
<html>
<head>
<title>Machine Total Calculator</title>
<script src="http://www.google.com/jsapi"></script>
<script>
google.load("jquery", "1.4.1");
</script>
<script>
var db = window.openDatabase("Machines", "", "Arcade Machines", 1024*1000);
function insertMachine(name, amount) {
db.transaction(function(tx) {
tx.executeSql('INSERT INTO groupOne (name, amount) VALUES (?, ?)', [name, amount]);
});
}
function renderResults(tx, rs) {
e = $('#status');
e.html("");
for(var i=0; i < rs.rows.length; i++) {
r = rs.rows.item(i);
e.html(e.html() + 'id: ' + r['id'] + ', Name: ' + r['name'] + ', Amount: ' + r['amount'] + '<br>');
}
}
function renderRecords(name) {
db.transaction(function(tx) {
tx.executeSql('SELECT * FROM groupOne', [], renderResults);
});
}
$(document).ready(function() {
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS groupOne(id INTEGER PRIMARY KEY, name TEXT, amount DECIMAL)', []);
});
$('#machine_form').submit(function() {
insertMachine($('#name').val(), $('#amount').val());
renderRecords();
return false;
});
renderRecords();
});
</script>
</head>
<body>
<form method="get" id="machine_form">
<div>
<input type="name" id="name" placeholder="Enter Machine Name" size="30"/>
<input type="number" current id="amount" placeholder="Amount" name="amount" size="15" />
<input type="submit" value="Add Machines" />
</div>
</form>
<div id="status">
</div>
</body>
</html>
좋아요, 그래서 행을 인쇄 할 위치에 버튼을 추가하여 ID를 업데이트 함수에 전달하고 그 안에 편집하고 업데이트하는 기능을 추가할까요? 나는 이것을 시도했지만 이드는 함수에 전달하지 않을 것이다 : e.html (e.html() + 'id :'+ r [ 'id'] + ', Name :'+ r [ 'name'] + ', 금액 :'+ r [ '금액'] + 'e'+ '
'); } – mark