简体   繁体   English

解决jquery ui手风琴子div

[英]Addressing jquery ui accordion child div

I have a page that has a dynamically created accordion with data on customers. 我有一个页面,其中包含根据客户数据动态创建的手风琴。 In the h3 headers of the accordion I have spans I can get data from for my ajax request. 在手风琴的h3标头中,我可以查找到我的Ajax请求的数据。 The problem is that all the accordions have a div in them that belong to the "pcom" class. 问题在于所有手风琴中都有一个属于“ pcom”类的div。 How can I address a particular "pcom" classed div? 如何处理分类为div的特定“ pcom”? I can get the data from the header by using the .find(), since the spans are children of the header. 我可以使用.find()从标头中获取数据,因为范围是标头的子级。 This won't work for addressing my divs as they are not children of the h3 header. 这不适用于处理我的div,因为它们不是h3标头的子级。 Any ideas? 有任何想法吗?

my js for the request: 我的请求的js:

    $("#accordion").accordion({
                collapsible: true,
                active: false,
                header: "h3",
                heightStyle: "content",
                activate: function() {

                var claddress = $('.ui-accordion-header-active').find("span.claddress").text();
                var clcity = $('.ui-accordion-header-active').find("span.clcity").text();
                var clprov = $('.ui-accordion-header-active').find("span.clprov").text();

                //if there is no claddress don't bother - (for accordion activate on close)
                if (claddress == '') {
                    //nothing there so do nothing
                    return;
                }
                //if we do have something check the pcom db for a match
                $.ajax({
                    url: "commenter.php",
                    datatype: "json",
                    data: {
                        clAddress: claddress,
                        clCity: clcity,
                        clProv: clprov
                    },
                    success: function(data) {
                        //we have a match now show it
                        //THIS IS WHERE I NEED TO ADDRESS THE pcom DIV IN THE ACCORDION
                    }
                });

            }
            });

Edit: This is how the accordion is built (just the success portion of the ajax is shown) 编辑:这是构建手风琴的方式(仅显示了ajax的成功部分)

                    success: function(data) {

                if(data == 'null') {
                buildaccordion("<h3>No Results Found</h3><div>No Data to Show.</div>");
                return;
                }

                var hbuild='';
                var tmp = $.parseJSON(data);
                //run a loop to build the HTML for each record
                $.each(tmp, function(i) {
                    //Header
                    hbuild += '<h3 class="sTitle">' + tmp[i].Name + ' - <span class="claddress">' + tmp[i].Address + '</span>, <span class="clcity">' 
                    + tmp[i].City + '</span>, <span class="clprov">' + tmp[i].Prov + '</span> - ' + tmp[i].CallInTime + '</h3>';

                    //Inner
                    hbuild += "<div>";
                    hbuild += '<ul class="menu">';
                    hbuild += '<li><a href="newcall.php?CustID=' + tmp[i].CustID + '">New Call</a></li>';
                    hbuild += '<li><a href="editcall.php?CustID=' + tmp[i].CustID + '">Edit Call</a></li>';
                    hbuild += '<li><a href="viewcall.php?CustID=' + tmp[i].CustID + '">Details</a></li>';
                    hbuild += '</ul>';
                    hbuild += '<div class="spcom">Persistent Comment Here</div>';
                    hbuild += '<div class="acname">Name: ' + tmp[i].Name + ' - <span class="ClientCust">Customer Num:' + tmp[i].ClientCustNum + '</span></div>';
                    hbuild += '<div class="acphone">Phone: ' + tmp[i].Phone + ' Ext#:' + tmp[i].PExt + '</div>';
                    hbuild += '<div class="acaddress">Address: ' + tmp[i].Address + ', ' + tmp[i].City + ', ' + tmp[i].Prov + ', ' + tmp[i].PCode + '</div>';
                    hbuild += '<div class="accontact">Contact: ' + tmp[i].Contact + '</div>';
                    hbuild += '<span class="acbilledto">Billed To: ' + tmp[i].BilledTo + '</span><br>';
                    hbuild += '<div class="acponum">PO Num: ' + tmp[i].PONum + '</div>';
                    hbuild += '<div class="acourpo">OurPO: ' + tmp[i].OurPO + '</div>';
                    hbuild += '<div class="acgivento">Service Provider: ' + tmp[i].GivenTo + '</div>';
                    hbuild += '<div class="acourwo">Accurate WO: ' + tmp[i].OurWO + '</div>';
                    hbuild += '<div class="acourinv">Accurate Invoice: ' + tmp[i].OurInv + '</div>';
                    hbuild += '<div class="acinvamt">Invoice Total: $' + tmp[i].InvAmt + '</div>';
                    hbuild += '<div class="accomments">Call Comments: ' + tmp[i].Comments + '</div>';
                    hbuild += "</div>";
                });
                //send it off to the build
                buildaccordion(hbuild);
                }

Now I could add an id containing a unique identifier in the pcom div at the time it is created (like a customer id) but doing that way would result in a id in the h3 header as well, thus it would get the id in the h3 header, and then reference the div. 现在,我可以在创建时在pcom div中添加一个包含唯一标识符的ID(例如客户ID),但是这样做也会在h3标头中生成一个ID,因此它将在h3标头,然后引用div。 But I would like to do this without hiding a ton of data in the tags of the accordion. 但是,我希望在此过程中不会在手风琴的标签中隐藏大量数据。 I had to do that on another page and it gets quite confusing and messy. 我不得不在另一页上这样做,它变得非常混乱和混乱。

Thanks for any help, Norst 感谢您的帮助,诺斯特

Assuming standard HTML structure like so: 假设标准HTML结构如下:

<h3><span>Section 1</span></h3>

<div>
    <p>
    Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
    ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
    amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
    odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
    </p>
</div>

And assuming that you're targeting H3 elements individually, you'd use: 并假设您分别定位H3元素,则可以使用:

$(this).next('div');

If you need to get that div from the span with the class you've matched, it would be: 如果您需要从跨度中获取与您匹配的类的div,则可能是:

$(this).parent('h3').next('div');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM