Problem with Javascript Object : TypeError
Hi everyone,
In my project I load a json object from thingworx and want to manipulate the content of this file.json.
The upload of the file from TW to Studio works fine, the code that is used for is:
// -- APERTURA FILE JSON --
var MODEL_JSON = {
'carrello': 'prova.json'
}
console.log('load MODEL_JSON files');
$scope.GetJsonFromTwxRepository = function (path) {
$scope.$applyAsync(function () {
$rootScope.$broadcast('app.mdl.Thing-Repository.svc.LoadJSON',
{
"path": path
}
);
}
, 500);
console.log("after call of GetJsonFromTwxRepository")
};
$scope.modelDataDynamic = [];
$scope.$on('$ionicView.afterEnter', function () {
console.log('Calling service');
angular.forEach(MODEL_JSON, function (value, key) { // nel nostro caso: value --> 'carrello', key --> 'prova.json'
$scope.GetJsonFromTwxRepository('/' + value);
console.log(value);
console.log("$ionicView.afterEnter was called ");
$scope.$root.$on('LoadJSON-complete', function (event, args) {
console.log("LoadJSON-complete event");
//will print to console the event name - LoadJSON-Complete
//console.log("name=" + event.name)
//console.log(event);
//console.log(args.data);
// the data was the event returns
$scope.COMP_LOCs = args.data // here we will set the data to global vars
//console.log(JSON.stringify($scope.COMP_LOCs))//print to the console to check the data
$scope.modelDataDynamic[key] = args.data;
//this a double check we will convert it to string and parse it back to json
//this will ensure that data is correct and has the correct syntax
}
);
});
}
)
After launching the preview mode of Vuforia, I could see the object like represented in the attached image.
The Json file has the following structure:
{"repair_sequence": [{
"traino":[ { "type": "sequence_isometric_1", "lang":"it", "description":[ "Rimuovere la flangia indicata in rosa",
"Rimuovere lamiera indicata in rosa svitando le apposite viti di serraggio",
"Svitare le viti e rimuovere lamiera di copertura posteriore",
"Togliere la lamiera superiore svitando viti di serraggio",
"Rimuovere il listello per procedere ad ispezione della trasmissione meccanica"
] },
{ "lang":"en", "description":[ "Remove the flange indicated in pink",
"Remove the sheet indicated in pink by unscrewing the appropriate tightening screws",
"Unscrew the screws and remove the rear cover plate",
"Remove the upper sheet by unscrewing the clamping screws",
"Remove the strip to inspect the mechanical transmission"
]}
]},
{
"traino":[ { "type": "sequence_isometric_2", "lang":"it", "description":[ "Rimuovere la trasmissione meccanica dal carrello",
"Rimuovere connettore Rockwell indicato dal flash rosa",
"Rimuovere il motore indicato in rosa, fare attenzione all'estrazione dell'albero. ",
"Rimuovere il basamento estraendo le viti di supporto"
] },
{ "lang":"en", "description":[ "Remove the mechanical transmission from the carriage",
"Remove Rockwell connector indicated by the pink flash",
"Remove the motor indicated in pink, pay attention to the extraction of the shaft",
"Rimuovere il basamento estraendo le viti di supporto"
] }
]
}
]
}
When I try to access to one string typed into the file in inspection mode, the console text: "TypeError: Cannot read property 'carrello' of undefined".
The print command that I used for this: console.log($scope.modelDataDynamic.repair_sequence[0].traino[0].description[0]);
Anyone has a solution? Thank you

