English 中文(简体)
使用美元的问题?
原标题:problem in use of $.each?

价值units的:salam/strong> &salavat: [这一数值插入json_encode(]]

salam:

[{“名称”: “salam”,”price_units”: “74,554”,“check Box_units”:[“minibar”、“mobleman”]},{“名称_units”:“mokhles”,“price_units”:”4,851,269”,“check Box_units”:[mobleman”,"tv”},{“name_units”:“fadat”,“price_units”:85,642”,“check_units”:[[barmini,”

salavat:

[{“名称_units”:“chaker”,”price_units”:“5,452”,“check Box_units”:null},{“名称_units”:“khobe”,“price_units”:“5,452,545”,“check_units”:[“minibar”、“mobleman”]}]

例如,做以下工作:

http://www.binboy.gigfa.com/admin/tour_foreign/insert_foreign”rel=“nofollow” DEMO1 - in here work my Code & 。 此处的DEMO2-in是显示所有代码

<>First。 请插入价值:sala <>/strong> in content => This have "tow” results, 请点击每一项成果:salam<>/strong>或salavat。 - 设计; 在此情况下,必须有三个数值,因为我们点击了salam =>salam &mokhles &fadat

<>2>。 请插入价值:salam=>结果有一例(salam)。 - 设计;

无论如何,我想到的是“5”或“3”价值或“Etc”数值,即<代码>与点击的字数相关的“units。

$( .auto_complete ).keyup(function () {
    var dataObj = $(this).closest( form ).serialize();
    $.ajax({
        type: "POST",
        dataType:  json ,
        //url:  http://binboy.gigfa.com/admin/tour_foreign/auto_complete ,
        url:  auto_complete ,
        data: dataObj,
        cache: false,
        success: function (data) {
            var id_name = $( .list_autobox_hotel ).attr( id );
            $( .list_autobox_hotel ).show().html(  );
            if (data == 0) {
                $( .list_autobox_hotel ).show().html( <p><b>there is no</b></p> );
            } else {
                $.each(data, function (index, value) {
                    $( <p id="  + value.name +  ">  + value.name +  </p> ).appendTo( .list_autobox_hotel );
                });
                //////////////////////*HERE//////////////////////
                $( .list_autobox_hotel p ).click(function (e) {
                    e.preventDefault();
                    var ac = $(this).attr( id );
                    $.each(data, function (index, value) {
                        $.each(value.units, function (bu, key) {
                            alert(key.name_units);
                        });
                    });
                    $(this).remove();
                    return false;
                });
                //////////////////////HERE*//////////////////////

                $( body ).click(function () {
                    $(".list_autobox_hotel p").hide().remove();
                    $( .auto_complete ).val(  );
                    $( .list_autobox_hotel ).show().html(  );
                    $( .list_autobox_hotel ).css( display ,  none );
                });

            }
        },
        "error": function (x, y, z) {
            // callback to run if an error occurs
            alert("An error has occured:
" + x + "
" + y + "
" + z);
        }
    });
});

<><>UPDATE:

(但这不是工作,还有同样的问题)

$( .list_autobox_hotel p ).bind("click", function (e) {
    e.preventDefault();
    var ac = $(this).attr( id );
    $.each(data, function (index, value) {
        $.each(value.units, function (bu, key) {
            alert(key.name_units);                
        });
    });
    $(this).remove();
    return false;
});

i don t understand "filter the data depending on what item you click on" and not know how is it!?

<><>UPDATE 2

Did this is true? (but this don t work and there is alert: undefined)

$( .list_autobox_hotel p ).bind("click", function (e) {
    e.preventDefault();
    var ac = $(this).attr( id );
    var ok = $.grep(data, function (e) {
        return e.name == ac;
    }).units;
    alert(ok);
    $(this).remove();
    return false;
});
最佳回答

That is because your code doesn t care which item you click on, it always shows all the data anyway.

You should either bind the click event inside the loop where you add the items, so that you can use the specific data for each item, or filter the data depending on what item you click on.

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签