嗨,我是猫鼬新人,有角度的离子。我正在尝试构建一个应用程序并遇到问题。我不知道如果这个语法mongoose是正确的,因为它仍然无法在我的前端工作,用户选择并回答并将其保存到数据库
继承我的猫鼬问题.js
var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
var Question = require('../models/Question.js');
var app = express();
// GET questions listing. questions/yourroute
router.get('/', function(req, res, next) {
Question.find(function(err, questions){
if(err) return next(err);
res.json(questions);
});
});
router.post('/saved-questions', function(req, res){
var now = Date()
User.findById(user.id, function(err, user){
var newanswer1 = {
question: '58ccb991caf9756f8e1d8a6c',
answer_text: req.body.Q1,
postdate: now
}
});
user.users_answers.push(newanswer1);
//repeat for Q 2 and 3, push each time
User.save()
});
module.exports = router;
这是离子的形式。我不知道为什么它不起作用,也许它是如何将它置于离子形式。假设有离子问题的幻灯片,每个可能的答案都在离子复选框中
<div id="questions" ng-controller="QCntrl">
<ion-content>
<ion-slide-box>
<ion-slide>
<div class="intro" ng-controller="PopupCtrl">
<h1 class="hidden">Intro Question</h1>
<h3>Just need to ask some questions to make this app personalized for you</h3>
<button class="button" value="next" ng-click="nextSlide()">OKAY</button>
<button class="button2 button-positive" ng-click="PopAlert()">
Why?
</button>
</div>
</ion-slide>
<ion-slide>
<div id="Q1box">
<h2>{{questions[0].question_text}}</h2>
<ul>
<li data-ng-repeat="answer in answers1">
<ion-checkbox id="Q1" ng-model="filter.users_answers">{{answer.label}}</ion- checkbox>
</li>
</ul>
<a href="#" ng-click="next()">Next Question</a>
</div>
</ion-slide>
答案 0 :(得分:0)
如果您有User.save()
,请尝试将其更改为user.save
并移动})
之前的User.save
并将其放在您更改{{1}之后的位置转到User.save
您正在使用user.save
修改刚刚找到的用户,但您似乎想要保存对User.findById(user.id, function(err, user){
user.users_answers
应该为您做的推送