javascript 我想在更换和退货中过滤序列,如果它用于维修

sdnqo3pr  于 2023-01-29  发布在  Java
关注(0)|答案(1)|浏览(102)

我试过这个

$.ajax({
        url: '/api/serials/index/',
        method: 'GET',
        data: {
            reference_no: $(this).val()
        },
        success: function (response) {
            let items_repairs = response[items_repairs];
            let items_replaces = response[items_returns];
    
            $('#repair_serial_no').empty().append('<option></option>');
            let filteredResponse = response[0].filter(function(item) {
                //Check if the serial is already used in the repair and return table
                let usedInRepair = items_repairs.serial_no.indexOf(item.serial_no) !== -1;
                let usedInReplaces = items_replaces.serial_no.indexOf(item.serial_no) !== -1;
                if(!usedInRepair && !usedInReplaces) {
                    return item;
                }
            });
            filteredResponse.forEach(item => {
                let template = `<option value="${item.id}">${item.serial_no}</option>`;
                $('#return_serial_no').append(template);
            });

但是当我点击点击选择没有显示序列号
在我的/api/序列/索引/

public function index(Request $request)
    {
        $serials = SerialNumber::where('reference_no', $request->reference_no)->get(['id', 'serial_no']);
        $items_repairs = ItemsRepair::all();
        $items_returns = ItemsReturn::all();
        $items_replaces = ItemsReplace::all();
        return response()->json([$serials,$items_repairs,$items_returns,$items_replaces]);
vjrehmav

vjrehmav1#

我想你忘了把键设置成字符串了。

$.ajax({
...
success: function (response) {
            let items_repairs = response['items_repairs'];
            let items_replaces = response['items_returns'];
...
}

相关问题