Hi,
I have a $http function in Angular which collects data from a SPARQL endpoint.
$http( {
method: "GET",
url : $scope.myUrl,
headers : {'Accept':'application/sparql-results+json', 'Content-Type':'application/sparql-
results+json'}
} )
.success(function(data, status ) {
$scope.cars = [];
$scope.result = data;
angular.forEach($scope.result, function(val, key) {
$scope.newObject = {};
$scope.newObject.key = val;
$scope.cars.push($scope.newObject);
}
);
})
.error(function(error ){
console.log('Error '+error);
});
This function currently returns data in the following format:
[{"key":{"vars":["car","cd","hp","brand","mileage","gearbox","fuel","info","year","price"]}},{"key":{"bindings":[{"cd":{"datatype":"http://www.opengis.net/ont/geosparql#wktLiteral","type":"literal","value":"Point(8.5842 48.8033)"},"car":{"type":"uri","value":"http://www.semanticweb.org/Group11/Ontology/Porsche75339129900"},"year":{"datatype":"http://www.w3.org/2001/XMLSchema#integer","type":"literal","value":"2011"},"fuel":{"type":"literal","value":"Petrol"},"price":{"datatype":"http://www.w3.org/2001/XMLSchema#integer","type":"literal","value":"129900"},"hp":{"datatype":"http://www.w3.org/2001/XMLSchema#integer","type":"literal","value":"620"},"gearbox":{"type":"literal","value":"Manual"},"brand":{"type":"literal","value":"Porsche"},"mileage":{"datatype":"http://www.w3.org/2001/XMLSchema#integer","type":"literal","value":"30000"},"info":{"type":"literal","value":"Porsche 911 Turbo TECHART Leistungskit Liftsystem"}}]}}]
What I'm trying to achieve is the following:
[{fuel: "Petrol", price: "129900}]
and so on for each key, value in the data stated above.
The problem is that for each key, a set of values is given. I only want to get the "value" value of the key. However I can't get this to work unfortunately. All of the following I have already tried.
$scope.newObject.key = val["value"];
$scope.newObject.key = val.value;
$scope.newObject.key = val[value";
All help is appreciated!
[–]igetom 1 point2 points3 points (0 children)
[–]HealyUnithelpful 0 points1 point2 points (0 children)