English 中文(简体)
环绕循环的每次迭代周围的 jjquery 折叠 div [闭
原标题:jquery wrap div around each iteration of loop [closed]
  • 时间:2012-05-25 14:00:01
  •  标签:
  • jquery
  • json

此代码从正在做 json_ encode 的 php 文件中获取数据, 它正在从 csv 文件中提取信息 。 我希望在第二个循环中能够有一个父数据, 围绕每组数值。 我用新的 Div2 尝试过这一点, 但是它用. sub_ row 将每个. field 和. sub_ row 包在一起 。

代替此:

 <div class="row"> // This one happens to only have one payment
     <div class="sum_field">Total: 79.99</div>
          <div class="field">BENV5239</div> // Details of payment
          <div class="field">11111</div>
</div>
 <div class="row"> // Based on Vendor ID
     <div class="sum_field">Total: 2487.01</div> // Sums up all payments for that Vendor
     <div class="field">BENV2137</div>
     <div class="field">11111</div>
     <div class="field">BENV2137</div>
     <div class="field">111111</div>
</div>
<div class="row"></div> // Another Vendor ID

应当:

 <div class="row">
     <div class="sum_field">Total: 200.00</div>
     <div class="sub_row">  // one payment
          <div class="field">BENV5239</div> // Details of payment
          <div class="field">11111</div>
     </div>
</div>
 <div class="row">
     <div class="sum_field">Total: 2487.01</div>
  <div class="sub_row"> // each payment that has the same vendor id is in it s own div
     <div class="field">BENV2137</div> 
     <div class="field">11111</div>
 </div>
 <div class="sub_row">
     <div class="field">BENV2137</div>
     <div class="field">111111</div>
 </div>
</div>

PHP 代码码

 $(document).ready(function() {
 $.getJSON( WF-XML.php , function(data) {

    //JSON.stringify(data); 
    var prevCardCode =   ;
    var newDiv;

    $.each(data, function(index, element) {
        if (element[ CardCode ] != prevCardCode) {
            newDiv = $( <div/> ).addClass( row ).appendTo( #showdata );
            $( <div class="sum_field">  +  Total:   + element[ payment_sum ] +  </div> ).appendTo(newDiv);      
            }
        prevCardCode = element[ CardCode ];

        $.each(element, function(key, value) {

            switch (key) {
                case  InvKey :
                case  PostDate :
                case  City :
                break;

                default:
                //newDiv2 = $( <div/> ).addClass( sub_row ).appendTo( .row );
                $( <div class="field">  + value +  </div> ).appendTo(newDiv);
                break;
                 }
             });
         });
     });
  });

JSON - 我翻翻了两次,第一次我只打印了这笔金额( 正在SQL内部计算, 第二次打印了其余的信息 ) 。 您可以看到最后的2个对象是同一销售商的 Id 。 因此, 我希望这能给每个新销售商加上一个父付款项, 然后给每个个人付款。 我的代码已经将每组付款都用父付款项包起来, 但我无法找到如何用父付款项包起来 。

 {"VendorID":"BENV5239","payment_sum":"79.99","Address":"525 Sapper St.","ZipCode":"19116"},
 {"VendorID":"BENV2137","payment_sum":"2487.01","InvPayAmnt":"108.92","Address":"340 Middle Road","ZipCode":"19037"},
 {"VendorID":"BENV2137","payment_sum":"2487.01","InvPayAmnt":"57.60","Address":"340 North Middle Road","ZipCode":"19037"}
最佳回答
 $(document).ready(function() {
 $.getJSON( WF-XML.php , function(data) {

//JSON.stringify(data); 
var prevCardCode =   ;
var newDiv;

$.each(data, function(index, element) {
    if (element[ CardCode ] != prevCardCode) {
        newDiv = $( <div/> ).addClass( row ).appendTo( #showdata );
        $( <div class="sum_field">  +  Total:   + element[ payment_sum ] +  </div> ).appendTo(newDiv);      
        }
    newDiv2 = $( <div/> ).addClass( sub_row ).appendTo(newDiv);
    prevCardCode = element[ CardCode ];

    $.each(element, function(key, value) {

        switch (key) {
            case  InvKey :
            case  PostDate :
            case  City :
            break;

            default:
            //newDiv2 = $( <div/> ).addClass( sub_row ).appendTo( .row );
            $( <div class="field">  + value +  </div> ).appendTo(newDiv2);
            break;
             }
         });
     });
 });

});

问题回答

暂无回答




相关问题
JQuery/MVC Search Issue

I have inherited a piece of work where the entry screen shows a summary of 20 calculated variables. E.g. Var A (250), Var B (79). Clicking on any of these links takes the user to a view with a ...

jQuery quicksearch plug-in tinkering with JSON

I ve implemented the quicksearch plugin by Rik Lomas and I love it for an application in a custom CMS I m building. I was wondering though, since I m going to have a bizillion items in the table if ...

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

PHP json_decode question

i m trying to use json_decode to combine a few json objects and then re-encode it. my json looks like: { "core": { "segment": [ { "id": 7, "...

Converting JSON data to Java object

I want to be able to access properties from a JSON string within my Java action method. The string is available by simply saying myJsonString = object.getJson(). Below is an example of what the string ...

热门标签