how to reduce javascript lines by jason file?
i have created one experience in which there are 1000 lines of javascripts and i want to reduce to few lines ? how to achieve this by editing JSON file? can anyone help in this?
i have created one experience in which there are 1000 lines of javascripts and i want to reduce to few lines ? how to achieve this by editing JSON file? can anyone help in this?
Hi
additional to the info provided by
So, in some case the usage of JSON construct could be very helpful when you for example assignee some property of object so you can do this in the Json file and then interpret this file in you js code. To read a json file you can use some construct like this:
//Global Variables
var pjson ="mfg.json";
var jsonData;
gotJSON=function(data){
console.log("gotJSON:Working on DATA >>>>"+data);
console.warn(data);
try{jsonData=JSON.parse(data);} catch(ex){console.log('exception');console.warn(ex);}
$scope.view.wdg.JSONList.list=jsonData.Steps;
$scope.view.wdg.JSONList.label='Title';
$scope.view.wdg.JSONList.value=jsonData.Steps[0].Title;
}
doRead=function (jsonFile){
fetch(jsonFile)
.then(response=>response.text())
.then(data=>gotJSON(data))
}
$scope.Init=function() {
doRead('./app/resources/Uploaded/'+pjson);
}
/////
$scope.$on('$ionicView.afterEnter',function(){
$scope.Init();})
Depending on this what your json file implements then you can do different things -. for e.g. setting multiple property:
$scope.app.JsonTest= function(){
//store in a global variabe some json properties for testing
//
var b={"chuck":{"visible":false,"shader":""},"chuckHolder":{"visible":false,"opacity":"1"},"chipHolder":{"visible":false,"opacity":"1"},
"chipScrew":{"visible":false,"shader":""},"chipBolt":{"visible":false,"opacity":"1"},"estop":{"visible":false,"opacity":"1"},
"frontDecal":{"visible":false,"shader":""},"spindleDecal":{"visible":false,"opacity":"1"},"estopFront":{"visible":false,"opacity":"1"}
}
$scope.JsonTestList=b;
$scope.setMutipleProps($scope.JsonTestList);
}
//======= definition of set multiple props
$scope.setMutipleProps= function(obj){
Object.keys(obj).forEach(function (item){
for(var prop in obj[item])
{
console.log("obj["+item+"]["+prop+"]="+obj[item][prop] )
$scope.view.wdg[item][prop]=obj[item][prop]
console.log("==>$scope.view.wdg["+item+"]["+prop+"]="+obj[item][prop] ) }
})
};
This and a lot of other things - but as already mentioned above this depend on your application case but also on your imagination, creativity and last but not least on your javascript skills.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.