我曾经使用restangular来从数据库中取出普通对象,并且我通过对取出的数据使用restangular plain()方法来解决它。但是现在我在将数据分配给外部范围变量时遇到了麻烦。演示代码 -
我已加载所有功能 -
function loadAll() {
var feelings = [];
Restangular.all('feelings').getList().then(function(data) {
angular.forEach(data.plain(), function(feeling) {
feelings.push(feeling);
})
})
console.log(feelings) // shows empty array :( , how to sole this issue
//----------------------------------------
// i wants my data like this to be returned
var feelings = [{
feeling_name: 'best',
view_count: 50
}, {
feeling_name: 'funny',
view_count: 150
}, {
feeling_name: 'angry',
view_count: 40
}, {
feeling_name: 'loved',
view_count: 42
}]
//-----------------------------------------------
return feelings.map(function(feeling) {
feeling.value = feeling.feeling_name.toLowerCase();
return feeling;
});
}