2017-07-19 57 views
-2

我打印出來的數據有問題。不能顯示AngularJS中的數組數據

{{orders}} =  
    [{"item":"DELL","quantity":6,"price":144}, 
    {"item":"Samsung","quantity":3,"price":3131}, 
    {"item":"222222","quantity":1,"price":31}, 
    {"item":"111111111","quantity":1,"price":13}] 

我嘗試查看

<div ng-repeat="order in orders track by $index"> 
    <span>{{ order[$index].item }} 
    </span> 
    </div> 

並沒有什麼。有人可以幫助我嗎?

編輯: 還不行

{{訂單}}

<div ng-repeat="order in orders track by $index"> 
<span> 
    {{order.item}} 
</span> 

並沒有什麼

控制器:

$scope.ListOfOrders = function() { 
     return ApiService.cart.list().then(function (resp) { 
      $scope.orders = resp[0].order; 
      console.log(resp[0].order) 
     }); 
} 
+0

order是數組中的項目,所以'{{order.item}}或'{{orders [$ index] .item}}'顯示該項目。 – Fetrarij

+0

學習一些教程 – charlietfl

回答

3

UI

<div ng-repeat="order in orders track by $index"> 
<span>{{order.item}}</span> 
</div> 

控制器

$scope.orders = [{ 
    "item": "DELL", 
    "quantity": 6, 
    "price": 144 
    }, { 
    "item": "Samsung", 
    "quantity": 3, 
    "price": 3131 
    }, { 
    "item": "222222", 
    "quantity": 1, 
    "price": 31 
    }, { 
    "item": "111111111", 
    "quantity": 1, 
    "price": 13 
    }] 

工作Solution

+0

我做EDIT POST可以再看一下,有什麼錯誤? –

+0

什麼是控制檯打印'resp [0] .order'? –

+0

[{「item」:「DELL」,「quantity」:6,「price」:144},{「item」:「ziemniaki」,「quantity」:3,「price」:3131},{「item」 :「Wisnie」,「quantity」:1,「price」:31},{「item」:「111111111」,「quantity」:1,「price」:13}] –

1

在每一個你並不需要綁定order[$index],NG-重演重申對象所以只寫:

<div ng-repeat="order in orders track by $index"> 
    <span>{{ order.item }} 
    </span> 
</div>