Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
532 views
in Technique[技术] by (71.8m points)

jquery - How to place select2 process results to tr class

When I rendered the HTML data, the following code was loading the HTML data with the success function:

$(document).on("change", ".product", function() {
        var selectval = $(this);
        $.ajax({
            url: '/purchase-order/ajax/load-attrs/',
            type: "POST",
            dataType: 'json',
            data: {
                'product': $(this).parents('tr').find(".product").val()
            },
            success: function (data) {
                selectval.parents('tr').find(".product_attr").html(data);
                console.log(data)
            }
        });
    });

All I need is: How do I populate data in a specific class in the Select 2 process result? How do I use this selectval.parents('tr').find(".product_attr") inside processResults?

$(document).on("change", ".product", function() {
            var selectval = $(this);
            $.ajax({
                url: '/purchase-order/ajax/load-attrs/',
                type: "POST",
                dataType: 'json',
                data: {
                    'product': $(this).parents('tr').find(".product").val()
                },
                processResults: function (data) {
    
                    return {
                        results: $.map(data, function (item) {
                            return {id: item.id, text: item.sku};
                        })
                    };
                },
                success: function (data) {
                    selectval.parents('tr').find(".product_attr").html(data);
                    console.log(data)
                }
            });
        });

Any help would be greatly appreciated


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...