Solved

help formatting the array / data

Posted on 2013-05-31
7
298 Views
Last Modified: 2013-08-11
I have the following jquery code
$(document).ready(function () {
	var BankRows = "";
        var prefRows = "";
        var detailBankInfo;
        var BankactionInfo = {
            'entityCount' : {^SFT:PAC:BankList_Count^},
            'actualEntityId' : {^SFT:TRN:Bank ID^},	 
            'actualAppId' : {^SFT:APL:Applicant ID^}, 
            'actualType' : "{^SFT:TRN:Bankaction Sub Type^}", 
            'entityList' : []									 
			
        };
        if (BankactionInfo.entityCount == 0) { BankactionInfo.entityCount = 1; }

        if ({^SFT:PAC:ProductID|TRN:ProductPackage:blankreplace(0)^} > 0)
        {
	        {^DRP:PAC:BankList_Count|TRN:ProductPackage()
		   
			   detailBankInfo = {
                    'id' : "{^UDT:BankCode^}",
                    'entityCode' : 'TRN',
                    'type' : "{^CFT:TRN:CreditPayroll^}",
                    'BankType': "{^UDT:BankSubType^}"
                };
				 BankactionInfo.entityList.push(detailBankInfo);
            /DRP:PAC:BankList_Count^}
        };
	
        BankRows = createBankListing(BankactionInfo);
        $('#BankListing').append(BankRows);
    });

Open in new window


that generates the following array/data
transInfo =  {
                    'id' : "404828",
                    'entitycode' : "Credit Limit",
                    'type' : "01160",
                    'Bank': "ABC123"
               };
            
        transInfo =  {
                    'id' : "404821",
                    'entitycode' : "Credit Limit",
                    'type' : "01163",
                    'Bank': "DEF322"                };
                       
          transInfo =  {
                    'id' : "404338",
                    'entitycode' : "Debit Limit",
                    'type' : "03320",
                    'Bank': "XYZ223"
                };
           
           transInfo =  {
                    'id' : "45558",
                    'entitycode' : "Credit Limit",
                    'type' : "03230",
                    'Bank': "DEC445"
                };
            
            transInfo =  {
                    
                    'id' : "404831",
                    'entitycode' : "Credit Limit",
                    'type' : "08730",
                    'Bank': "DWC765"
                };

Open in new window


the first section of code retrieves the results from the db and loops through the reults and spits each record/data set out as a separate array.

My question is ... what do i need to change in the jquery section to output the data as follows?

transInfo =  {
                    'id' : "404828",
                    'entitycode' : "Credit Limit",
                    'type' : "01160",
                    'Bank': "ABC123"
               }, {
                    'id' : "404821",
                    'entitycode' : "Credit Limit",
                    'type' : "01163",
                    'Bank': "DEF322"
                }, {
                    'id' : "404338",
                    'entitycode' : "Debit Limit",
                    'type' : "03320",
                    'Bank': "XYZ223"
                }, {
                    'id' : "45558",
                    'entitycode' : "Credit Limit",
                    'type' : "03230",
                    'Bank': "DEC445"
                }, {
                   'id' : "404831",
                    'entitycode' : "Credit Limit",
                    'type' : "08730",
                    'Bank': "DWC765"
                };

Open in new window


Thanks
0
Comment
Question by:nriddock
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39212533
You first script does not match the output. I do not see a loop and I see no transinfo anywhere
Also you likely want
Transinfo = [
   {
    },
    {
     }
];
0
 

Accepted Solution

by:
nriddock earned 0 total points
ID: 39229550
Sorry for the mixup. Heres the updated code

$(document).ready(function () {
	var BankRows = "";
        var prefRows = "";
        var detailTransInfo;
        var transactionInfo = {
            'entityCount' : {^SFT:PAC:BankList_Count^},
            'actualEntityId' : {^SFT:TRN:Bank ID^},	 
            'actualAppId' : {^SFT:APL:Applicant ID^}, 
            'actualType' : "{^SFT:TRN:Bankaction Sub Type^}", 
            'entityList' : []									 
			
        };
        if (transactionInfo.entityCount == 0) { transactionInfo.entityCount = 1; }

        if ({^SFT:PAC:ProductID|TRN:ProductPackage:blankreplace(0)^} > 0)
        {
	        {^DRP:PAC:BankList_Count|TRN:ProductPackage()
		   
	detailTransInfo = {
                    'id' : "{^UDT:BankCode^}",
                    'entityCode' : 'TRN',
                    'type' : "{^CFT:TRN:CreditPayroll^}",
                    'BankType': "{^UDT:BankSubType^}"
                };
				 transactionInfo.entityList.push(detailTransInfo);
            /DRP:PAC:TransList_Count^}
        };
	
        BankRows = createBankListing(transactionInfo);
        $('#BankListing').append(BankRows);
    });

Open in new window


This is the output it produces
detailTransInfo  =  {
                    'id' : "404828",
                    'entitycode' : "Credit Limit",
                    'type' : "01160",
                    'Bank': "ABC123"
               };
            
        detailTransInfo =  {
                    'id' : "404821",
                    'entitycode' : "Credit Limit",
                    'type' : "01163",
                    'Bank': "DEF322"                };
                       
          detailTransInfo  =  {
                    'id' : "404338",
                    'entitycode' : "Debit Limit",
                    'type' : "03320",
                    'Bank': "XYZ223"
                };
           
           detailTransInfo =  {
                    'id' : "45558",
                    'entitycode' : "Credit Limit",
                    'type' : "03230",
                    'Bank': "DEC445"
                };
            
            detailTransInfo =  {
                    
                    'id' : "404831",
                    'entitycode' : "Credit Limit",
                    'type' : "08730",
                    'Bank': "DWC765"
                };

Open in new window


This is how i need the output
detailTransInfo =  {
                    'id' : "404828",
                    'entitycode' : "Credit Limit",
                    'type' : "01160",
                    'Bank': "ABC123"
               }, {
                    'id' : "404821",
                    'entitycode' : "Credit Limit",
                    'type' : "01163",
                    'Bank': "DEF322"
                }, {
                    'id' : "404338",
                    'entitycode' : "Debit Limit",
                    'type' : "03320",
                    'Bank': "XYZ223"
                }, {
                    'id' : "45558",
                    'entitycode' : "Credit Limit",
                    'type' : "03230",
                    'Bank': "DEC445"
                }, {
                   'id' : "404831",
                    'entitycode' : "Credit Limit",
                    'type' : "08730",
                    'Bank': "DWC765"
                };

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39229584
I do not understand what code this is. What's with the ^ ??

Assuming it is some kind of template scripting language I guess

THIS:               {^DRP:PAC:BankList_Count|TRN:ProductPackage()

is a loop

so something like


if ({^SFT:PAC:ProductID|TRN:ProductPackage:blankreplace(0)^} > 0)
        {
              {^DRP:PAC:BankList_Count|TRN:ProductPackage()
               
                  var x = {
                    'id' : "{^UDT:BankCode^}",
                    'entityCode' : 'TRN',
                    'type' : "{^CFT:TRN:CreditPayroll^}",
                    'BankType': "{^UDT:BankSubType^}"
                };
                         transactionInfo.entityList.push(x);
            /DRP:PAC:TransList_Count^}
        };
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:nriddock
ID: 39229626
the ^ symbol signifies the code directly following is a "token" - internal code the vendor uses as a form of placeholder / variable., etc.

Ill give it a try. Thanks for all your help!
0
 

Author Comment

by:nriddock
ID: 39229646
its yielding the same results

its still writing
detailTransInfo  =  {
                    'id' : "404828",
                    'entitycode' : "Credit Limit",
                    'type' : "01160",
                    'Bank': "ABC123"
               };
            
        detailTransInfo =  {
                    'id' : "404821",
                    'entitycode' : "Credit Limit",
                    'type' : "01163",
                    'Bank': "DEF322"                };
                       

Open in new window

i need it to merge or combine the multiple "detailTransInfo" sections into one big "detailTransInfo"
detailTransInfo  =  {
                    'id' : "404828",
                    'entitycode' : "Credit Limit",
                    'type' : "01160",
                    'Bank': "ABC123"
               }; {
                    'id' : "404821",
                    'entitycode' : "Credit Limit",
                    'type' : "01163",
                    'Bank': "DEF322"                };
                       

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39230388
I am sorry. Since I do not know the nature of the code you post, I cannot help  you.
Please let us know what framework you are using
0
 

Author Closing Comment

by:nriddock
ID: 39399515
i figured out a different method
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question