首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有“[]”node.js的空白页

带有“[]”node.js的空白页
EN

Stack Overflow用户
提问于 2016-08-04 01:21:49
回答 1查看 103关注 0票数 0

我一直在尝试设置一个新的路由"Dashboard“,由于某种原因,当我开始处理它的Schema时,每当我试图访问websiteName/dashboard时,它都会显示一个带有”“的空白页面。我不知道发生了什么。

以下是我的路线:

代码语言:javascript
复制
const dashboardController = require('./controllers/dashboard');
app.get('/dashboard', passportConfig.isAuthenticated, dashboardController.getDashboard);
app.post('/dashboard', passportConfig.isAuthenticated, dashboardController.postCreateTodo);

控制器文件夹中的dashboard.js:

代码语言:javascript
复制
const async = require('async');
const crypto = require('crypto');
const nodemailer = require('nodemailer');
const passport = require('passport');
const User = require('../models/User');
const Todo = require('../models/Dashboard');

/**
 * GET /dashboard
 * 
 */

exports.getDashboard = function(req, res){
  Todo.find({userId: req.user.id}, function (err, todos) {
    if (err) return console.error(err);
    res.send(todos);
  });
};

/**
* POST /dashboard
* 
*/
exports.postCreateTodo = (req, res, next) => {
  User.create(req.body.todo, function(err, newTodo){
      if(err){
          res.render("new");
      } else {
          //then, redirect to the index
          res.redirect("/dashboard");
      }
  });
};

Dashboard.js inside models文件夹:

代码语言:javascript
复制
const bcrypt = require('bcrypt-nodejs');
const crypto = require('crypto');
const mongoose = require('mongoose');
const User = require('../models/User');

const todoSchema = new mongoose.Schema({
  name: {type: String, default : ''},
  User: {type: mongoose.Schema.ObjectId, ref: 'User'},
  createdAt  : {type : Date, default : Date.now}

});

const Todo = mongoose.model('Todo', todoSchema);
module.exports = Todo;

最后是dashboard.jade:

代码语言:javascript
复制
extends ../layout

block additionalCSS
  link(rel='stylesheet', type='text/css', href='assets/css/todos.css')
  link(href='https://fonts.googleapis.com/css?family=Roboto:400,700,500', rel='stylesheet', type='text/css')
  link(rel='stylesheet', type='text/css', href=' https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.css')
  link(rel='stylesheet', href='//cdnjs.cloudflare.com/ajax/libs/lemonade/2.1.0/lemonade.min.css')
  script(type='text/javascript', src='assets/plugins/jquery-3.0.0.min.js')


block content
  #container
    .page-header
      h3 Dashboard
    .frame
      .bit-2
        h1
          | Do 
          i.fa.fa-plus                      
        input(type='text', placeholder='Add New Todo')             
        ul
          li
            span
              i.fa.fa-trash
            |  Finish Daily Report               
          li
            span
              i.fa.fa-trash
            |  House on Fire              
          li
            span
              i.fa.fa-trash
            |  Crying Baby          
      .bit-2
        h1
          | Decide 
          i.fa.fa-plus             
        input(type='text', placeholder='Add New Todo')            
        ul
          li
            span
              i.fa.fa-trash
            |  Exercising              
          li
            span
              i.fa.fa-trash
            |  Calling Family And Friends             
          li
            span
              i.fa.fa-trash
            |  Long-term Biz Strategy
    |         
    .frame
      .bit-2
        h1
          | Delegate 
          i.fa.fa-plus             
        input(type='text', placeholder='Add New Todo')            
        ul
          li
            span
              i.fa.fa-trash
            |  Scheduling Interviews              
          li
            span
              i.fa.fa-trash
            |  Booking Flights               
          li
            span
              i.fa.fa-trash
            |  Answering Certain emails          
      .bit-2
        h1
          | Delete 
          i.fa.fa-plus            
        input(type='text', placeholder='Add New Todo')             
        ul
          li
            span
              i.fa.fa-trash
            |  Watching Television             
          li
            span
              i.fa.fa-trash
            |  Checking Social Media               
          li
            span
              i.fa.fa-trash
            |  Surfing The Web

block additionalJS  
script(type='text/javascript', src='assets/js/todos.js')

注意:我还没有完成将表单和值从CRUD请求的模式添加到dashboard.jade中

非常感谢您的帮助,感谢您花时间阅读本文。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-04 01:41:01

您并没有呈现您的dashboard.jade视图,您当前只是使用JSON (res.send(todos))响应GET请求。

我的猜测是你打算用res.render('dashboard', { todos: todos })或者类似的东西来代替res.send(todos)

此外,在不相关的说明中,当Todo.find()失败并出现错误时,您不会重新发送获取请求。您至少应该以res.send(500)或其他方式响应,以向客户端指示内部错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38750040

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档