Angular JS ng-repeater不填充2D数组数据

时间:2015-05-19 04:24:25

标签: angularjs multidimensional-array angularjs-ng-repeat

我目前正在开发一个测试应用程序。当我使用ng-repeater填充数据时,它当前显示空字段。但是当我在console.log数组中时,它显示的是正确的数据。

订购控制器

(function()
{
    var injectParams = ['$stateParams'];

    function orderController($stateParams) {
        var vm = this;

        var customerId = $stateParams.id;
        customers = [
            {
                id: 1,
                joined: '2000-12-02',
                name: 'John',
                city: 'Chandler',
                orderTotal: 9.9956,
                orders: [
                    {
                        id: 1,
                        product: 'Shoes',
                        total: 9.9956
                    }
                ]
            },
            {
                id: 2,
                joined: '1965-01-25',
                name: 'Zed',
                city: 'Las Vegas',
                orderTotal: 19.99,
                orders: [
                    {
                        id: 2,
                        product: 'Baseball',
                        total: 9.995
                    },
                    {
                        id: 3,
                        product: 'Bat',
                        total: 9.995
                    }
                ]
            },
            {
                id: 3,
                joined: '1944-06-15',
                name: 'Tina',
                city: 'New York',
                orderTotal: 44.99,
                orders: [
                    {
                        id: 4,
                        product: 'Headphones',
                        total: 44.99
                    }
                ]
            },
            {
                id: 4,
                joined: '1995-03-28',
                name: 'Dave',
                city: 'Seattle',
                orderTotal: 101.50,
                orders: [
                    {
                        id: 5,
                        product: 'Kindle',
                        total: 101.50
                    }
                ]
            }
        ];

        //load customers to view

        vm.orders = [];


        var result = customers;

        function loadCustomers()
        {

            for (var i = 0; i < result.length; i++)
            {
                if (result[i].id == parseInt(customerId)) 
                {
                    vm.orders.push(result[i].orders);

                }
            }
        }

        loadCustomers();

        console.log(vm.orders);
    };

    orderController.$inject = injectParams;

    angular.module('app')
    .controller('orderController', orderController);

      }());

ORDERS HTML

         <div class="row">
       <div class="small-12 columns">
        <h1>ORDERS</h1>
        <table>
            <tr>
                <th>ID</th>
                <th>Product</th>
                <th>Total</th>
            </tr>
            <tr ng-repeat="order in aT.orders">
                <td>{{ order.id }}</td>
                <td>{{ order.product }}</td>
                <td>{{ order.total }}</td>
            </tr>
        </table>
    </div><!--small-12 columns-->
</div><!--row-->

APP.JS

      //Initialise Foundation

      $(document).foundation();

      //Initialise Module

      (function ()
      {

    angular.module('app', ['ui.router'])

    .config(function ($stateProvider, $urlRouterProvider)
    {
        $urlRouterProvider.otherwise('/customers');

        $stateProvider
            .state('customers',
            {
                url: '/customers',
                templateUrl: 'app/views/customers.html',
                controller: 'customerController',
                controllerAs: 'aT',
            })
            .state('orders',
            {
                url: '/orders/:id',
                templateUrl: 'app/views/orders.html',
                controller: 'orderController',
                controllerAs: 'aT',
            });
       });

    }());

2 个答案:

答案 0 :(得分:1)

如果public HexagonDrawable(int color) { paint.setColor(color); paint.setPathEffect(new CornerPathEffect(6)); // added hexagon.setFillType(Path.FillType.EVEN_ODD); } 是一个数组数组,则需要两个中继器。我不确定您为何客户订单推送到import pandas as pd import numpy as np td = np.array([32,34,36,38,40,42,44,51,53,152,283])*1e9 # if you don't multiply by 1e9, then pandas will assume you are referring to nanoseconds when you use the function pd.to_datetime() df = pd.DataFrame({'td':td, 'val': np.random.rand(11)}) df.index = pd.to_datetime(df.td) df.index = df.index.time # select the time component of the index ... ignoring the date df.drop('td', 1, inplace=True) print df val 00:00:32 0.825991 00:00:34 0.578752 00:00:36 0.348558 00:00:38 0.221674 00:00:40 0.706031 00:00:42 0.912452 00:00:44 0.448185 00:00:51 0.368867 00:00:53 0.188401 00:02:32 0.855828 00:04:43 0.494732 df.plot() # it gets the plot you want ,因为您似乎正在按客户ID搜索,这似乎是{{1 }}。我只想将值赋给orders,即

orders

您当前的模板应该可以使用这些数据。

答案 1 :(得分:1)

您需要将数组附加到范围

JS:

// declare a module
var app = angular.module('myApp', []);

// configure the module.
// in this example we will create a greeting filter
app.controller('CustomerController', ['$scope', 
    function($scope) {
        $scope.customers = [
            {
                id: 1,
                joined: '2000-12-02',
                name: 'John',
                city: 'Chandler',
                orderTotal: 9.9956,
                orders: [
                    {
                        id: 1,
                        product: 'Shoes',
                        total: 9.9956
                    }
                ]
            },
            {
                id: 2,
                joined: '1965-01-25',
                name: 'Zed',
                city: 'Las Vegas',
                orderTotal: 19.99,
                orders: [
                    {
                        id: 2,
                        product: 'Baseball',
                        total: 9.995
                    },
                    {
                        id: 3,
                        product: 'Bat',
                        total: 9.995
                    }
                ]
            },
            {
                id: 3,
                joined: '1944-06-15',
                name: 'Tina',
                city: 'New York',
                orderTotal: 44.99,
                orders: [
                    {
                        id: 4,
                        product: 'Headphones',
                        total: 44.99
                    }
                ]
            },
            {
                id: 4,
                joined: '1995-03-28',
                name: 'Dave',
                city: 'Seattle',
                orderTotal: 101.50,
                orders: [
                    {
                        id: 5,
                        product: 'Kindle',
                        total: 101.50
                    }
                ]
            }
        ];
    }
]);

HTML:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body ng-app="myApp">
    <div ng-controller="CustomerController">
        <div ng-repeat="customer in customers">
            {{customer}}
        </div>

    </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular.min.js"></script>

    <script src="scripts.js"></script>
</body>
</html>