Как пройти область с переменной в JQuery? - PullRequest
0 голосов
/ 21 сентября 2009

У меня есть строка html, которую мне нужно вставить во входное выделение, но оно выходит за рамки того, где находится входное выделение ... Я думаю, видите переменную параметров, которую я создаю? Он должен быть внутри следующего выбора после любого из классов .product ... пожалуйста, сообщите.

    $(".product").change(function(){

        //get selected option of the select that changed
        var selected = $(this).val();
        //then create the url to reference the value of the selected option (product id)
        var url = "/order/getpricing/" + selected;

        //remove all options from that nearby select statement
        $(this).next('select').children().remove();

        var pricelist = $(this).next('select');

        $.getJSON(url, function(data, pricelist){

            var options = '';
            for(n = 0; n < data.length; n++){
                options += '<option value="' + data[n].volumeID + '">' + explainPricing(data, n) + '</option>';
                //setMeGlobal(options, "options");
                }

                $("#"+pricelist).html(options);


                //TODO NEXT: SOMEHOW ADD OPTIONS TO THE SELECT!


        });

        $(this).next('select').html = options;

    });

1 Ответ

2 голосов
/ 21 сентября 2009

Попробуйте максимально использовать переменную pricelist. Он автоматически доступен вашему обработчику ajax без необходимости передавать его:

$(".product").change(function(){

    //get selected option of the select that changed
    var selected = $(this).val();
    //then create the url to reference the value of the selected option (product id)
    var url = "/order/getpricing/" + selected;

    var pricelist = $(this).next('select');

    //remove all options from that nearby select statement
    pricelist.find('option').remove();

    $.getJSON(url, function(data) {

        var options = '';
        for(n = 0; n < data.length; n++){
            options += '<option value="' + data[n].volumeID + '">' + explainPricing(data, n) + '</option>';
            //setMeGlobal(options, "options");
        }

        pricelist.html(options);
    });
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...