簡體   English   中英

是否可以使用Jquery的每個函數獲取表行的父級和子級?

[英]Is it possible to get the parent and child of table row using each function of Jquery?

我有關於插入每個項目的父項和子項的問題。 我想分別將父和子插入數據庫。 我會告訴你們我的問題的偽代碼。 以下我給jsfiddle ,這是一個網絡應用程序就像一個餐廳的WEB POS。

我設計了這樣的網絡應用程序,有一個子項目或稱為調味品。

喜歡這個

偽代碼:

  1. 在表數據庫A中插入Main項。

  2. 主項目已經插入數據庫表A之后。在Ajax的成功函數內部。 如果此主項目具有子項目,則設置條件。 如果Main項具有Sub Item,則獲取Main項的最后一個插入,並在數據庫的表B中插入Sub項。 否則,如果主項目沒有子項目,則主項目將僅插入表格A.

輸出應該在數據庫上。

防爆。

表A(僅主要項目表) 表A.

表B(子項目表) 表B.

 $('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> 

據我所知 - 你想使用數據庫上下文來添加數據庫中的實體?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM