0
제품 세부 정보 (productId, name, quantityonhand)를위한 웹 저장소를 만들고 서버에서 해당 저장소로 레코드를 채 웁니다. 필요한 수량을 주문을 수락 할 수 있는지 여부를 확인해야합니다.HTML5 순차 실행
제품 양식에는 웹 저장소에서 사용할 수있는 모든 제품에 대한 체크 박스 (이름 = "제품")와 필요한 수량을 수용하는 해당 텍스트 입력 필드가 있습니다.
유효성 검사 방법은 다음과 같이 정의됩니다. 이 코드 때문에 db.transaction의 비동기 특성, 실행
은function productValidation(){
for(i=0;i<document.Products.product.length;i++){
// checking whether the product has been checked/choosen
if (document.Products.product[i].checked==true){
var productId = document.Products.product[i].value;
var qty = document.Products.p[i].value;
var db = systemDB;
// validating the available quantity
db.transaction(
function(transaction){
transaction.executeSql('select * from product where productId=?;',
[productId],
function(transaction, results){
for (var j=0; j<results.rows.length; j++) {
var row = results.rows.item(j);
if (qty>row['qoh']){
alert(
row['productname']
+ ' is out of stock. We can serve you only '
+ row['qoh'] + ' quantities currently!');
document.Products.product[i].checked = false;
document.Products.p[i].value = 0;
}
}
});
}
);
}
}
return false;
}
, 외부 루프가 실행지고있어 검증이 지난 제품 선택이 끝난에서만 일어나고있다.
이 문제를 해결할 수 있도록 도와주세요. 나는 그 실행이 순차적으로 일어나기를 바란다.
Yuvi 함께 체인하는 db.transaction에 대한 콜백 함수를 호출