我在插入每个项目的父项和子项时遇到问题。 我想将父项和子项分别插入数据库。我将向大家展示我问题的伪代码。在下面,我给出 jsfiddle ,这是一个Web应用程序,就像餐馆的WEB POS。
我这样设计我的网络应用,有一个子项或称其为调味品。
伪代码:
在表数据库A中插入Main项目。
在Main项目已经插入数据库表A之后。在Ajax成功函数的内部。如果此主要项目具有子项目,则设置条件。如果主项目具有子项目,则获取主项目的最后一个插入项,并将子项目插入数据库的表B中。否则,如果主项目没有子项目,则主项目将仅插入表A中。
输出应该在数据库上。
例如。
$('button#add_to_cart').on('click', function() {
var customer_id = $('#hidden_customer_id').val();
var z = $('#noun_chaining_order').find('tr.condimentParent');
var x = $('#noun_chaining_order').find('tr.editCondiments').add(x).add(z).each(function() {
var $tds_menu = $(this).find("td");
Qty_menu = $tds_menu.eq(0).text(),
Item_menu = $tds_menu.eq(1).text(),
Price_menu = $tds_menu.eq(2).text();
console.log(this);
console.log(Item_menu);
});
});
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title></title>
</head>
<body>
<table class="table table-hover upsize_check" id="noun_chaining_order" style="border:none;">
<input type="hidden" name="" value="" id="hidden_customer_id">
<thead>
<tr style="font-size: 15px; color:white;">
<th scope="col">Qty</th>
<th scope="col">Items</th>
<th scope="col">Price</th>
<th>Action</th>
</tr>
</thead>
<tbody style="font-size:14px;" id="tbody_noun_chaining_order">
<tr class="condimentParent">
<td></td>
<td>$5.00 Extra Crispy 2 Piece Box</td>
<td class="total">5.00</td>
<td><button class="removeorderWithCondi btn btn-danger form-control">Delete</button></td>
</tr>
<tr class="editCondiments">
<td class="condiments_order_quantity">2</td>
<td>*Standard</td>
<td class="total">0.00</td>
<td class="allow_to_open_condiments_conditional" style="display:none;">Yes</td>
<td class="condi_section_id" style="display:none;">3</td>
</tr>
<tr class="editCondiments">
<td class="condiments_order_quantity">2</td>
<td>*Individual Fries</td>
<td class="total">0.00</td>
<td class="allow_to_open_condiments_conditional" style="display:none;">Yes</td>
<td class="condi_section_id" style="display:none;">2</td>
</tr>
<tr class="editCondiments">
<td class="condiments_order_quantity">1</td>
<td>*Buttery Bread</td>
<td class="total">0.00</td>
<td class="allow_to_open_condiments_conditional" style="display:none;">No</td>
<td class="condi_section_id" style="display:none;">4</td>
</tr>
<tr class="editCondiments">
<td class="condiments_order_quantity">1</td>
<td>*Chocolate Chip Cookie</td>
<td class="total">0.00</td>
<td class="allow_to_open_condiments_conditional" style="display:none;">No</td>
<td class="condi_section_id" style="display:none;">5</td>
</tr>
<tr class="editCondiments">
<td class="condiments_order_quantity">1</td>
<td>*355ml Pepsi</td>
<td class="total">0.00</td>
<td class="allow_to_open_condiments_conditional" style="display:none;">No</td>
<td class="condi_section_id" style="display:none;">6</td>
</tr>
</tbody>
</table>
<center>
<button type="button" class="btn btn-primary" style="background-color:#3D0081; border-color:#3D0081;" id="add_to_cart">Click to process the order</button>
</center>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
答案 0 :(得分:0)
据我了解-您要使用数据库上下文以便在数据库中添加实体?