有没有一种方法可以使用jquery来获取每个带有/不带有子代的表行?

时间:2019-04-17 07:18:33

标签: jquery laravel

我在将项目插入数据库时​​遇到问题,我感到困惑,如何获取每个带有或不带有子代的表行。稍后,我将向大家展示我的输出,

我的输出。

First Insert

您会看到数字(1)和数字(2)有一个子项,数字(3)没有子项。

插入项目的逻辑就是这些

第一种情况(复杂)

方案:首先在父项插入之后插入父项,以获取最后一个插入ID,然后插入具有父项ID的子项。

第二种情况(基本部分)

方案:如果父项没有子项,则首先插入父项,因为父项没有子项,将停止在下一个表上插入

我手动创建的数据库中的示例输出是这个。

第一张表

enter image description here

第二张表

Why does the order of media queries matter in CSS?

我的控制器示例

public function insert_wish_list_menu_order(Request $request) {


    $now = new DateTime();


    DB::insert('INSERT INTO wish_list_menu_order (customer_id,wish_list_menu_name,wish_list_total_price,wish_created_at) 
        VALUES(?,?,?,?) ',[

         $customer_id,
         $item,
         $price,
         $now,
    ]);

    return response()->json('Successfully Inserted');

} 


public function insert_wish_list_menu_belong_condiments(Request $request) {


    $Qty = $request->get('Qty');
    $Item = $request->get('Item');
    $Cost = $request->get('Cost');

    $now = new DateTime();

    $last_id_insert = DB::select('SELECT max(wish_menu_id) as id FROM wish_list_menu_order');

    foreach($last_id_insert as $result)
    {
      $id_last_inserted = $result->id;

    }

    DB::insert('INSERT INTO wish_list_menu_belong_condiments (wish_menu_id,belong_condi_name,belong_condi_qty,belong_condi_price,belong_condi_created) 
        VALUES(?,?,?,?,?) ',[

         $id_last_inserted,
         $Item,
         $Qty,
         $Cost,
         $now


    ]);

    return response()->json('Successfully Inserted');


} 

我的提交功能

    $('button#add_to_cart').on('click',function () {
    var customer_id = $('#hidden_customer_id').val();


      $('#noun_chaining_order').find('tr.condimentParent').each(function (i) {

          var $tds = $(this).find('td'),
          Qty = $tds.eq(0).text(),
          Item = $tds.eq(1).text(),
          Price = $tds.eq(2).text();
          console.log(Item);


      });

      $('#noun_chaining_order').find('tr.editCondiments').each(function (i) {

            var $tds = $(this).find('td'),
            Qty = $tds.eq(0).text(),
            Item = $tds.eq(1).text(),
            Cost = $tds.eq(2).text();
            console.log(Item);

      });


});

0 个答案:

没有答案