这是我的剧本:
items
我需要将for循环中的所有插入数据都插入到单个数组中,但不能得到任何东西。为什么我得到阵列。 []空白。你能帮我么。谢谢。
答案 0 :(得分:0)
function createSlots(experiences){
return new Promise(function(resolve,reject){
var slots = req.body.availableSlots;
slots = JSON.parse( slots );
var count = slots.length;
var array = [];
for(var i=0;i<count;i++){
var date = slots[i].date;
var timeAvailability = slots[i].time;
//console.log(timeAvailability);
var availability = new Availability({
'expId':experiences._id,
'availabilitydate': date,
'availabilityslots': JSON.stringify(timeAvailability)
});
//console.log(availability);
availability.save(function(err,availability){
if(err){
reject(err);
}else{
if(availability){
resolve();
}else{
reject(err);
}
}
});
array.push(availability);
}
console.log(array);
var obj = {experience : experiences, availability:array}
resolve(obj);
});
}