Convert One field in an Object Array data with angularjs and Javascript to another value -
in angularjs controller have code:
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 = []; (var name in data) { values.push(data[name]); } $scope.items = values; }); // order date , time $scope.orderprop = 'ac'; } ); it creates object array name items. key values labed aa, ab, ac etc. when user inputs data drop down menu, want save values like: 1,2,3,4,5 , when data imported website, convert values back. 0 = bad; 5 = very good. so, every record key name ae want convert values 1,2,3,4,5 bad, okay, fair, good, good.
i can figure out program flow, need know how reference values using object oriented javascript guess.
the data structured this:
c5_200630_option 1 aa:"option 1" ab:"toyota" ac:6499 ad:"truck" ae:"tacoma, silver, 1/2 ton 4wd" af:4 i ran of code:
alert(object.keys($scope.useditems)); and gives values of 0,1,2,3,4 etc. guess key values in $scope.useditems numbers. don't know how access key , value data specifically. simple way can display in alert content of array is?
i used line:
alert(data[name].ad); and reference data in every record name ad. gives me way identify specific item in record.
okay, figured out solution:
if (data[name].af === "3") { data[name].af = "awesome!"; } even though figured out solution problem, still have no idea i'm doing. if there better way, let me know.
you can define array this
var example = ["bad", "not bad", "fine", "good", "very good"]; and instead of checking value of data[name].af every time can set this
data[name].af = example[data[name].af]; which gives result want want data[name].af=3 should fine , example[3] want...
Comments
Post a Comment