下面是我的代码,用于计算集合并将其存储在全局变量计数器中。问题是它返回undefined。
_getCount : function(role){
var Users = new collections.Users();
var counter = 0;
var self = this;
Users.baucis(
{
conditions: { role : role },
count: true
}
).then(function ( ) {
counter = count;
//console.log(counter);
});
console.log(counter);
return counter;
},
答案 0 :(得分:1)
行count
上的counter = count;
变量无处声明。
你应该使用类似的东西:
_getCount : function(role){
var Users = new collections.Users();
var counter = 0;
var self = this;
Users.baucis(
{
conditions: { role : role },
count: true
}
).then(function ( ) {
counter = Users.length;
//console.log(counter);
});
console.log(counter);
return counter;
},
Users.length
正在收集underscore method。