将json元素名称与表的类名匹配

时间:2016-01-13 12:32:01

标签: jquery html css

这是mainObject的内容



      var mainObject={"Main":[{
	  "I_Have": [
		{	"typeofAcc":"casa",
			"key":"MyMainSavings",
			"MyMainSavings": {
				"MyMainSavingsTop": {
					"AccountName": "MyMainSavings",
					"AccountNumber": "x726",
					"Balance": "USD 5,600.00",
					"Rate":""
				},
				"MyMainSavingsBottom": 
				[
					{
						"Available": "Available",
						"Value": "$4329"
					},
					{"Clear": "Clear","Value": "$3456"},
					{"Hold": "Hold","Value": "$5000"}
				]
			}
		},
		{
			"key":"MyEverydayExpenses",
			"MyEverydayExpenses": {
				"MyEverydayExpensesTop": {
					"AccountName": "MyMainSavings",
					"AccountNumber": "x726",
					"Balance": "USD 600.00",
					"Rate":""
				},
				"MyEverydayExpensesBottom": 
				[
					{"Available": "Available","Value": "$4329"},
					{"Clear": "Clear","Value": "$3456"},
					{"Hold": "Hold","Value": "$7300"}
				]
			}
		},
		{
			"key":"FavDeposit",
			"FavDeposit": {
				"FavDepositTop": {
					"AccountName": "MyMainSavings",
					"AccountNumber": "x726",
					"Balance": "USD 5,000.00",
					"Rate": "@4.5%"
				},
				"FavDepositBottom": 
				[
					{"MaturityValue": "Maturity Value","Value": "$4009"},
					{"Term": "Term","Value": "$1156"},
					{"MaturesOn": "Matures On","Value": "$5000"}
				]
			}
		},
		{
			"key":"MyDeposit",
			"MyDeposit": {
				"MyDepositTop": {
					"AccountName": "MyMainSavings",
					"AccountNumber": "x726",
					"Balance": "USD 8,600.00",
					"Rate": "@4.5%"
				},
				"MyDepositBottom": 
				[
					{"MaturityValue": "Maturity Value","Value": "$4329"},
					{"Term": "Term","Value": "$3456"},
					{"MaturesOn": "Matures On","Value": "$5000"}
				]
			}
		}
	]
      },			
         {				"I_Owe" :[
			
            {"key":"HomeLoan",
			"HomeLoan":
					{	
					  "HomeLoanTop":
						{
							"AccountName":"MyMainSavings",
							"AccountNumber":"x726",
							"Balance":"USD 5,600.00",
							"Rate":"@4.5% floating"
						},		
					 "HomeLoanBottom":
						[
							{"Installment":"Installment","Value":"$4329" }, 
							{"Disbursed":"Disbursed","Value":"$3456" }, 
							{"CurrentDues":"Current Dues","Value":"$5000" }
						]                 
                    }
			},				
			{"key":"Ruby",
				"Ruby":
					{
					  "RubyTop":
						{
							"AccountName":"MyMainSavings",
							"AccountNumber":"x726",
							"Balance":"USD 600.00",
							"Rate":""
						},		
					 "RubyBottom":
						[
							{"$6500 Dues":"$6500 Dues","Value":"$4329" }, 
							{"Minimum Due":"Minimum Due","Value":"$3456" }, 
							{"Unbilled":"Unbilled","Value":"$7300" }
						]                 
                    }
			},
			{"key":"MyOverdraft",	
			"MyOverdraft":
					{
					  "MyOverdraftTop":
						{
							"AccountName":"MyMainSavings",
							"AccountNumber":"x726",
							"Balance":"USD 5,000.00",
							"Rate":""	
						},		
					 "MyOverdraftBottom":
						[
							{"Available":"Available","Value":"$4009" }, 
							{"Unclear":"Unclear","Value":"$1156" }, 
							{"Sanc_Limit":"Sanc. Limit","Value":"$5000" }
						]			
                    }					
			}					
		]
         }]}




我试图遍历json数据,即var mainObject = {...}使用for循环。但是我无法将table的className与x(在for循环中定义的变量)的元素的className相匹配指着。



        $("<div>", {class: "wrapper"}).append(
        $("<div>", {class: "LeftSection"}).append(
            $("<div>", {class: "MyMainSavings"}).append(
				$("<div>", {class: "MyMainSavingsTop"}).append($("<table>",{class:         "MyMainSavingsTop"})).append($(table456)),
				$("<div>", {class: "MyMainSavingsBottom"}).append($("<table>",              {class: "tablebottom"}))
			),
			$("<div>", {class: "MyEverydayExpenses"}).append(
				$("<div>", {class: "MyEverydayExpensesTop"}).append($("<table>",            {class: "MyEverydayExpensesTop"})),
				$("<div>", {class: "MyEverydayExpensesBottom"}).append($("                    <table>",{class: "tablebottom"}))
			),
			$("<div>", {class: "MyDeposit"}).append(
				$("<div>", {class: "MyDepositTop"}).append($("<table>",{class:               "MyDepositTop"})),
				$("<div>", {class: "MyDepositBottom"}).append($("<table>",{class:             "tablebottom"}))
			),
			$("<div>", {class: "FavDeposit"}).append(
				$("<div>", {class: "FavDepositTop"}).append($("<table>",{class:             "FavDepositTop"})),
				$("<div>", {class: "FavDepositBottom"}).append($("<table>",{class:             "tablebottom"}))
			)
        ), 
        $("<div>", {class: "RightSection"}).append(
			$("<div>", {class: "HomeLoan"}).append(
				$("<div>", {class: "HomeLoanTop"}).append($("<table>",{class:               "HomeLoanTop"})),
				$("<div>", {class: "HomeLoanBottom"}).append($("<table>",{class:             "tablebottom"}))
			),
			$("<div>", {class: "Ruby"}).append(
				$("<div>", {class: "RubyTop"}).append($("<table>",{class:                     "RubyTop"})),
				$("<div>", {class: "RubyBottom"}).append($("<table>",{class:                     "tablebottom"}))
			),
			$("<div>", {class: "MyOverdraft"}).append(
				$("<div>", {class: "MyOverdraftTop"}).append($("<table>",{class:                 "MyOverdraftTop"})),
				$("<div>", {class: "MyOverdraftBottom"}).append($("<table>",                    {class: "tablebottom"}))
            )
    )).appendTo("body")
	
	
        for(var x in mainObject)
            {
	
	        //if("<table>".className == Object.getOwnPropertyNames(x))
	      if(mainObject.attr() == "<table>".className)
		{
			
		  for(i=0; i<x.prev().length; i++)
			{
				var table123 = $("<table>");
				var row = $('<tr></tr>').text(mainObject[x]);
				var table456 = table123.append(row);
			}
    		}
            }
&#13;
&#13;
&#13;

0 个答案:

没有答案