locked
How to bind array RRS feed

  • Question

  • User229488726 posted

    How to bind this type of array in javascript using data base 

    $scope.Citylist = []
    $scope.Citylist = [{
    date: '2015-02-28',
    time: '15:30',
    day: 'Saturday',
    children: [{
    object: 'rooms',
    additionalnote: 'complete',
    name: '1th Person',
    cost: '4500$'
    }]
    },
    {
    date: '2015-03-07',
    time: '08:30',
    day: 'Saturday',
    children: [{
    object: 'yards',
    additionalnote: 'nothing',
    name: '2th Person',
    cost: '3500$'
    }]
    },
    {
    date: '2015-03-17',
    time: '16:30',
    day: 'Tuesday',
    children: [{
    object: 'pools',
    additionalnote: 'nothing',
    name: '3th Person',
    cost: '2500$'
    }]
    }
    ];

    Monday, August 29, 2016 9:22 AM

Answers

  • User-1142886626 posted

    Hi brajalalbrp,

    It seems you used AngularJS Data Model. What is the “using data base”? As far as I know, the data model is a collection of data available for the application. There are several ways of displaying model data in the view.

    You can use the ng-bind directive.

    <p ng-bind="firstname"></p>

    You can also use double braces{{}}to display content from the model.

    <p>First name: {{firstname}}</p>

    Code below is for your reference:

    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
    <body>
           <div ng-app="myApp" ng-controller="myCtrl">
           <p >date1: {{Citylist[0].date}}</p>
           <p ng-bind="Citylist[0].time"></p> 
       <script type="text/javascript">
            var app = angular.module('myApp', []);
            app.controller('myCtrl', function ($scope) {
                $scope.Citylist =
                [{
                date: '2015-02-28',
                time: '15:30',
                day: 'Saturday',
                children: [{
                object: 'rooms',
                additionalnote: 'complete',
                name: '1th Person',
                cost: '4500$'
                }]
                },
                {
                date: '2015-03-07',
                time: '08:30',
                day: 'Saturday',
                children: [{
                object: 'yards',
                additionalnote: 'nothing',
                name: '2th Person',
                cost: '3500$'
                }]
                },
                {
                date: '2015-03-17',
                time: '16:30',
                day: 'Tuesday',
                children: [{
                object: 'pools',
                additionalnote: 'nothing',
                name: '3th Person',
                cost: '2500$'
                }]
                }
                ];
                $scope.Name = function (date) {
                    var desc = "";
                    angular.forEach($scope.attachmentLookup, function (attachemnt) {
                        if (parseInt(attachemnt.Citylist) == attachmentTypeId)
                            desc = attachemnt.attachmentDesc;
                    });
                    return desc;
                };
                })
        </script>
    </body>

    Best regards,

    Ailleen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 30, 2016 6:41 AM