我有像一些參數的URL這一個: http://localhost:9000/#/checkout/?title1=Sodadrink&quantity1=2&price1=129.95&title2=PolaryteGlasses&quantity2=1&price2=59.95#%2FAngularJS如何組/組織的目標項目,以顯示他們在視圖
,我讓他們與$location.search()
,剛剛返回他們罰款喜歡的對象:
Object
price1: "129.95"
price2: "59.95"
quantity1: "2"
quantity2: "1"
title1: "Sodastream"
title2: "Polaryte – Óculos de Sol"
__proto__: Object
這是很酷,但現在我需要像組每個項目:
[item]
title : Sodastream
price : 129.95
quantity : 1
[item]
title : ---
price : ---
quantity : ---
我被困在T他的部分,我已經計算了對象內的所有項目,6,並且他們通過創建一個新的對象將它們分組爲3,但是沒有成功。 你能幫我嗎?謝謝。
感謝您的快速回答,事實證明我正在考慮正確的方式,就像您和Mike的解決方案。我這樣計算內部物品: $ scope.basket = []; var items = $ location.search(); var count = 0; for(var k in items){ if(items.hasOwnProperty(k)){ ++ count; } } 其中計數將返回6號碼。然後我做了一個循環: for(var i = 1; i
我只是改變了你的代碼,因爲(var i = 1; i <= numOfItems; i ++) 在<運算符爲<=時,否則它只會將索引1推送到Output數組。 謝謝;) –
感謝您指出。乾杯。 –