Angularjs 如何在无模式mongoose中添加对象数组?
api.js,将数据发布到服务器 如何在数组中保存对象数组 ** //得救了 })) angularjs控制器 $scope.addProduct=function(){ }Angularjs 如何在无模式mongoose中添加对象数组?,angularjs,arrays,mongodb,mongoose,Angularjs,Arrays,Mongodb,Mongoose,api.js,将数据发布到服务器 如何在数组中保存对象数组 ** //得救了 })) angularjs控制器 $scope.addProduct=function(){ } 请查看此代码并帮助我!挣扎了几个星期。有一个像[“name”:carrot,“price”:24,“:”等]这样的对象数组。那些陷入困境的人参考这个数组,而不是使用这个方法 $scope.submitx = function(inv, item){ console.log(inv); v
请查看此代码并帮助我!挣扎了几个星期。有一个像[“name”:carrot,“price”:24,“:”等]这样的对象数组。那些陷入困境的人参考这个数组,而不是使用这个方法
$scope.submitx = function(inv, item){
console.log(inv);
var object = {
name:inv.name,
fname:items.fname,
totalValue: 0
}
PostBlog.createInvoice(objects).then(function(data){
console.log(data);
});
$scope.objects= {};
}
router.post('/invoices',函数(req,res){//通过从
var发票=新发票();
对于(变量i=0;i
你的问题不是很简洁,所以不难理解你在这里要做什么。如果我理解正确,你想在项中存储对象,但你不知道这些项的确切字段。在这种情况下,将项定义为项:[]
,而不是定义类似项:[item]
。现在,您可以将任何对象推入项中。
router.post('/objectss', function(req, res){
var object= new Object(); **
object.items.push({firstName: req.body.fname, lastName: req.body.lname});
object.name = req.body.name;
object.save(function (err) {
if(err) throw err;
res.json({success: true, message:'allahuakbar'});
});
$scope.items.push({
fname: $scope.item.fname,
lname: $scope.item.lname
});
$scope.item = {};
$scope.submitx = function(inv, item){
console.log(inv);
var object = {
name:inv.name,
fname:items.fname,
totalValue: 0
}
PostBlog.createInvoice(objects).then(function(data){
console.log(data);
});
$scope.objects= {};
}
router.post('/invoices', function(req, res){ //by making route in from
var invoice = new Invoice();
for (var i = 0; i < req.body.length; i++) {
invoice.items.push({name:req.body.fname[i].fname});
}
invoice.name = req.body.name;
//invoice.items.insertMany(items, function(error, next) {
invoice.save(function (err) {
if(err) throw err;
res.json({success: true, message:'allahuakbar'});
});
// saved!
});