var json=[];
json.push({"id":"1","name":"abc"});
json.push({"id":"2","name":"xyz"});
Run Code Online (Sandbox Code Playgroud)
在推开我的json之后
json=[{"id":"1","name":"abc"},{"id":"2","name":"xyz"}];
Run Code Online (Sandbox Code Playgroud)
在这里,我想清除所有json数据
像这样 json=[]
是否有可能在jquery或javascript?
无论如何,使用字符串变量调用角度服务
$scope.serviceList=["yearDetails","monthDetails","dayDetails"];
//controller
$scope.getDetails=function(type,index){
if(type==$scope.serviceList[index]){
// if i will call like this yearDetails.query(function(data){}); it is working
//here i am getting "yearDetails"
$scope.serviceList[index].query(function(data){
console.log(data);
});
}
}
//service
.factory('yearDetails', function($resource){
return $resource('/getyearDetails', {}, {
query: { method:'POST', params:{}, isArray:false }
});
})
.factory('monthDetails', function($resource){
return $resource('/getmonthDetails', {}, {
query: { method:'POST', params:{}, isArray:false }
});
})
.factory('dayDetails', function($resource){
return $resource('/getdayDetails', {}, {
query: { method:'POST', params:{}, isArray:false }
});
})
Run Code Online (Sandbox Code Playgroud)