无法在AngularJS中显示数组中的数据

时间:2017-07-19 11:58:56

标签: 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}]

我在View中尝试

  <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)
        });
}

2 个答案:

答案 0 :(得分:3)

<强> UI

s.push(42)

<强>控制器

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

正在使用 Solution

答案 1 :(得分:1)

你不需要绑定 $this->load->library('upload'); $config['upload_path'] = './uploads'; $config['allowed_types'] ='csv|xls|xlsx'; $config['max_size'] = 1024; //in KB $config['overwrite'] = TRUE; $config['encrypt_name'] = TRUE; $config['max_filename'] = 25; $this->upload->initialize($config); if (!$this->upload->do_upload('image_name')) { //if file upload failed then catch the errors $this->handle_error($this->upload->display_errors()); $is_file_error = TRUE; } else { //store the file info $image_data = $this->upload->data(); $config['image_library'] = 'gd2'; $config['source_image'] = $image_data['full_path']; //get original image $config['maintain_ratio'] = TRUE; $config['width'] = 150; $config['height'] = 100; $this->load->library('image_lib', $config); if (!$this->image_lib->resize()) { $this->handle_error($this->image_lib->display_errors()); } } ,ng-repeat本身遍历每个对象,所以只需写:

order[$index]