Within an angularjs controller, the following code is used:
var ysshControllers = angular.module('theControllers', []);
ysshControllers.controller('CommonController',
function($scope, $http, $route) {
$scope.dbKey = $route.current.customInput;
$scope.urlToDb = 'https://' + $scope.dbKey + '/.json';
$http.get($scope.urlToDb).success(function(data) {
var values = [];
for (var name in data) {
values.push(data[name]);
}
$scope.Items = values;
});
// Initially order by date and time
$scope.orderProp = 'ac';
}
);
This code creates an array object named Items
. The keys are labeled as aa
, ab
, ac
, etc. When a user inputs data from a dropdown menu, only values like 1,2,3,4,5
need to be saved. Upon importing back into the website, these values should be converted. For example, 0
corresponds to Bad
and 5
corresponds to Very Good
. Therefore, when dealing with records under the key name ae
, the numeric values 1,2,3,4,5 should be converted to text values: Bad, Okay, Fair, Good, Very Good.
The structure of the data looks like this:
C5_200630_Option 1
aa:"Option 1"
ab:"Toyota"
ac:6499
ad:"Truck"
ae:"Tacoma, Silver, 1/2 ton 4wd"
af:4
An attempt was made using the following line of code:
alert(Object.keys($scope.UsedItems));
This provided values such as 0,1,2,3,4
. It appears that the key values within $scope.UsedItems
are solely numbers. A method needs to be found to access both the key and value data specifically. Is there a simple way to display the content of the array contents in an alert?
By using this line:
alert(data[name].ad);
The data within each record with the name ad
can be referenced. This offers a means to pinpoint a specific item within the record.
A solution has been discovered:
if (data[name].af === "3") {
data[name].af = "Awesome!";
}
Despite the resolution of the problem at hand, there remains a lack of understanding regarding how to proceed further. If there exists a better approach, please advise.