의 값의 보류를 가져올 수 없습니다 내 코드자바 스크립트 : 오브젝트 여기
var dataGroupByParentCategory = function(data){
return _.groupBy(data, function(entry){
return entry.category.parent;
});
};
var parentCategorySum = function(data) {
var result = {};
_.forEach(_.keys(this.dataGroupByParentCategory(data)), function(parentCategory){
var that = this;
console.log(parentCategory);
var s = _.reduce(that.dataGroupByParentCategory[parentCategory], function(s, entry){
console.log('>' + entry); // Can not see entry here
return s + parseFloat(entry.amount);
}, 0);
result[parentCategory] = s;
});
return result;
};
및 데이터
'data': [
{
'category': {
'uri': '/categories/0b092e7c-4d2c-4eba-8c4e-80937c9e483d',
'parent': 'Food',
'name': 'Costco'
},
'amount': '15.0',
'debit': true
},
{
'category': {
'uri': '/categories/d6c10cd2-e285-4829-ad8d-c1dc1fdeea2e',
'parent': 'Food',
'name': 'India Bazaar'
},
'amount': '10.0',
'debit': true
},
{
'category': {
'uri': '/categories/d6c10cd2-e285-4829-ad8d-c1dc1fdeea2e',
'parent': 'Food',
'name': 'Sprouts'
},
'amount': '11.1',
'debit': true
}, ...
문제처럼 보인다?
console.log('>' + entry); // Can not see entry here
내가 자바 스크립트를 배우고 잘 범위의 개념에 정통하고 있지 않다 위의 코드와 같이 내가 그 여기에 문제를 일으키는되고, 항목의 값을 볼 수없는 이유는 무엇입니까?
되는'루프의 this' 외부 = VAR . @daydreamer가'_.forEach'를 사용하여'dataGroupByParentCategory'의 키를 반복하고 있으므로 Underscore의'.forEach' – elclanrs