как вставить данные в конкретный объект, используя angularjs?

0

Я добавил свой код. У меня есть список мобильных магазинов с широтой и долготой. Здесь я вычислил расстояние между точками до всех магазинов, и я показываю в консоли, но я хочу нажать это значение (_d) в каждый магазин. Пожалуйста, помогите мне.

В настоящее время он просто показывает:

Adtiya Samsung Store
[email protected]

sri shakthi mobile service
[email protected]

sun mobile service center
[email protected]

ragu mobile service center
[email protected]

Пожалуйста, помогите мне обновить этот S_clocation. Я боюсь здесь, потому что я новичок в этой технологии.

http://jsfiddle.net/rpbn6u23/16/

angular.module('myApp', [])
    .controller("myCntrl", function ($scope) {
    //$scope.query = " Regular Service,Hardware Faults,overall maintenance";
    $scope.dealers = [{
        
        S_Email_id: "[email protected]",
        S_Store: "samsung",
        Store_Name: "Adtiya Samsung Store",
        S_Services: "Regular Service,Software Faults,Hardware Faults",
        Store_long_description: "Undertake all kind of samsung mobiles",
        Store_short_description: "Undertake all kind of samsung mobiles",
		S_Latitude: "12.93489905",
		S_Longitude: "77.57070772",
		S_clocation: ""
    }, {
       
        S_Email_id: "[email protected]",
        S_Store: "nokia",
        Store_Name: "sri shakthi mobile service",
        S_Services: "Settings Faults,Regular Service,Hardware Faults",
        Store_long_description: "Undertake all kind of nokia mobiles",
        Store_short_description: "Undertake all kind of nokia mobiles",
		S_Latitude: "12.9599264",
		S_Longitude: "77.5924983",
		S_clocation: ""
    }, {
        
        S_Email_id: "[email protected]",
        S_Store: "nokia,samsung",
        Store_Name: "sun mobile service center",
        S_Services: "Regular Service,overall maintenance,Mobile Shield Installation",
        Store_long_description: "Undertake all kind of nokia,samsung mobiles",
        Store_short_description: "Undertake all kind of nokia,samsung mobiles",
		S_Latitude: "12.911229",
		S_Longitude: "77.519281",
		S_clocation:""
		},
	{
        
        S_Email_id: "[email protected]",
        S_Store: "nokia,samsung",
        Store_Name: "ragu mobile service center",
        S_Services: "Regular Service,overall maintenance,Mobile Shield Installation",
        Store_long_description: "Undertake all kind of nokia,samsung mobiles",
        Store_short_description: "Undertake all kind of nokia,samsung mobiles",
		S_Latitude: "12.909999",
		S_Longitude: "77.506871",
		S_clocation: ""
		}
    ]
	var _lat1 =12.904778 ;
	var _lon1 =77.585680;
	
              var d = $scope.dealers.length;
	for (var i = 0; i < d; i++) {



                            var _lat2 = $scope.dealers[i].S_Latitude;
                            var _lon2 = $scope.dealers[i].S_Longitude;

                            //--------------------------------------distance calculation-------------------------------------
                            function _getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) {
                                var R = 6371; // Radius of the earth in kilometers
                                var dLat = deg2rad(lat2 - lat1); // deg2rad below
                                var dLon = deg2rad(lon2 - lon1);
                                var a =
                                    Math.sin(dLat / 2) * Math.sin(dLat / 2) +
                                    Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
                                    Math.sin(dLon / 2) * Math.sin(dLon / 2);
                                var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
                                var d = R * c; // Distance in KM
                                return d;
                            }

                            function deg2rad(deg) {
                                return deg * (Math.PI / 180)
                            }



                            // precise value
                            var _d = "Precise value: " + _getDistanceFromLatLonInKm(_lat1, _lon1, _lat2, _lon2);




                            _d = Math.round(_getDistanceFromLatLonInKm(_lat1, _lon1, _lat2, _lon2) * 100) / 100;

							console.log(_d);

                            

                            //-----------------------------------------------------------------------------------------------
                        }
	}
)
<div ng-app="myApp">
    <div ng-controller="myCntrl">
        <label>Case sensitive Search on Label</label><br>
        <input ng-model="query" type="text" placeholder="Search for name" />
        
        
            <div ng-repeat="dealer in dealers">
                          
                {{dealer.Store_Name}}<br>
				{{dealer.S_Email_id}}<br>
				{{dealer.S_clocation}}<br>
				</div><br><br><br>
    
        </div>
		</div>
Теги:

1 ответ

0
Лучший ответ

У вас уже есть ссылка на ваш объект-дилер в вашем цикле: $scope.dealers[i]. Просто добавьте другое свойство к этому объекту.

$scope.dealers[i].distance = _d;

Затем вы можете отображать его на своей странице так же, как вы показываете другие свойства.

{{dealer.distance}}

См. Обновленный скрипт.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню