Tag: 帕格

在模板中循环,在用玉进行编译时,“无法读取属性长度”的“未定义”错误

所以这是get route / users / search的searchfunction: // peopleRoutes.js:25:16 exports.search = function (req, res) { var term = req.query.term; User.find({$or: [ {username: {$in: [term]}}, {bio: {$in: [term]}}, {location: {$in: [term]}} ]}, function (err, users) { var fn = jade.compileFile('path/to/template.jade'), {}); var html = fn(users); res.setHeader("Content-Type", 'text/html'); res.send(html); res.end(); }).sort({username: 'asc'}); }; 这是我想要检索的模板: ul.list-group(id='main-list') for user in […]

node.js和jade:显示来自属性值的内容 – 不显示的行

我相当肯定这可能是一个简单的问题,但不幸的是,我无法find正确的答案。 我所拥有的是一个数据库,里面有一些用于开始新行的自由文本。 目前我正在使用玉石作为框架。 当我尝试使用数据库中的值渲染页面时,\ n \ r不起作用,因为它们看起来只是在html源代码中没有解释的字符。 我的玉石看起来像这样: extends layout block content h1 #{doc.recipetitle} h3 Zutaten: p #{doc.ingredients} h3 Anleitung: p #{doc.recipe} h3 So siehts aus: img(src=doc.img) 我的问题是与doc.ingredients和doc.recipe ,因为这可能是像这样的值:potatotes \ r \ nbeef \ r \ nwater \ r \ n它显示为:土豆牛肉水 但我想要的是:土豆牛肉水 是否可以正确格式化段落?

Jade中的Node.js渲染variables

我想在我的视图中查看所有的URL,但是我得到#{data.id} Cannot read property 'id' of undefined错误的#{data.id} Cannot read property 'id' of undefined 。 我想创build一个循环并查看我拥有的所有video。 app.js app.get('/you', function(req,res) { youtube.where('id', '<', '5689').fetchAll().then(function(data) { res.render('youtube', { mi : data }); }); }); 这是一个给定ID的输出示例(我改变了res.render res.send来testing我的查询,所以它的工作原理) [ { "id": 442, "channel_name": "channelNameredacted", "video_url": "videoURlRedacted", "video_title": "redacted", "status": 1, "date": "redacted" } ] youtube.jade 假设我想输出videoID的。 html head body each […]

ajax调用来更新玉的部分模板

当我使用部分玉石模板更新div内容时遇到了麻烦。 第一个Ajax调用删除用户工作正常,div内容更新,但是当我再次点击删除其他用户时,不会调用ajax操作。 我看不出问题在哪里。 这是我的代码 视图/ layout.jade doctype html html head title= title link(rel='stylesheet', href='/stylesheets/style.css') body .container block content block footer script(type='text/javascript' src='/javascripts/jquery.min.js') script(type='text/javascript' src='/javascripts/functions.js') 视图/ index.jade extends layout block content include menu.jade #users_list include users.jade 视图/ users.jade table thead tr th Id th Name th Description th(colspan='2') Actions tbody if(users) each user in users tr […]

如何在jade中创build一个用于node.js的variables

我是新来expression节点,我负责一个Web应用程序的前端。 我需要能够让用户按下一个链接,并为该链接时,按下通过variablesindex.js此链接可以让用户select他们想要testing的问题类别。 我不认为每个类别有不同的路线是最好的select。 但因为我是新的,我不知道该怎么做。 这里是我的链接在玉的代码(我想添加一些东西在这里做我想做的)有一个链接到本文底部的页面截图。 li.active a(href='freeplay') i.fa.fa-edit span.nav-label Freeplay span.fa.arrow ul.nav.nav-second-level li a(href='freeplay/category') Category1 li a(href='freeplay/category') Category2 li a(href='freeplay/category') Category3 li a(href='freeplay/category') Category4 li a(href='freeplay/category') Category5 这是我的index.js处理它。 temp是我想要保存类别的string的variables。 //Handle the free play request router.get('/freeplay' , isAuthenticated, freeplay.startFreePlay); //Handle the free play request with category router.get('/freeplay/category' , isAuthenticated, freeplay.startCategoryPlay); 最后node.js,我想能够读取variables中的温度是variables我想分配用户select的类别。 exports.startFreePlay = function(req, res) { […]

玉:双数据编号“”“”

在我的.jade ,我用_id设置了一个data-id一个mondodb的用户模型,问题是这个翡翠用双""""保存它。 这是玉 body(data-id = user._id) 这是HTML中的输出 data-id="567ab00e5a09b86915937f9b" 如果我尝试 body(id = user._id) 那么输出是 id=""567ab00e5a09b86915937f9b"" 我不明白这个问题。 先谢谢你

快递 – 玉不能find意见

我目前正在学习Express(+ Node.js),并且遇到了一个奇怪的错误: Error: Failed to lookup view "index" in views directory "../NODE_tests/Tutorial/app/views" 在../NODE_tests/Tutorial/app/views中有一个index.jade doctype 5 html body h1 Hellow World! 和我的app.js是(应该是)正确的: // require the stuff we need var express = require("express"); var logger = require("morgan"); var http = require('http'); // build the app var app = express(); // Set the view directory to /views app.set('views', […]

node.js – 在POST请求中发送一个整数作为input参数

我试图从用户(.jade页面)input一个整数,并将该值作为身体parameter passing。 当我尝试使用下面的代码时,该值正在转换为string。 你能帮我吗? app.js var empid = req.body.empid; // getting value from the jade page console.log(empid); // output here is 1111 var requestdata = {1:empid}; console.log(requestdata); // output here is '1111' var options = { url: my URL goes here, method: 'POST', headers: { 'Content-Type': 'application/json' }, auth: { user : username, pass : […]

浏览器不会重新加载吞吐和livereload

请原谅,如果这可能看起来像一个重复的问题,但我已经阅读了每一个资源,我可以find帮助我确定我的问题的根源。 我正在编译一个jade文件后,尝试让gulp重新加载Chrome浏览器。 我有这个为我的gulpfile.js: var gulp = require('gulp'), jade = require('gulp-jade'), connect = require('gulp-connect'); gulp.task('jade', function() { return gulp.src('src/*.jade') .pipe(jade({pretty: true})) .pipe(gulp.dest('dev/')) .pipe(connect.reload()) }); gulp.task('connect', function() { connect.server({ livereload: true, root: 'dev', debug: true }); }) gulp.task('watch', function() { gulp.watch('src/*.jade', ['jade']); }); gulp.task('default', ['connect', 'watch']); 我的文件结构是: . ├── dev/ │ └── index.html ├── node_modules/ ├── src/ […]

如何在页面中包含AngularJS

我正在做一个NodeJS应用程序,我想用我的客户端脚本AngularJS。 我通过NPM下载了AngularJS,现在我试图让它在我的页面中实现,出于某种原因,我的请求不起作用。 任何人都可以帮我包括AngularJS文件? 发布页面。 extends layout block content script(src="/javascripts/postCtrl.js") // Page Content .container(ng-app='postModule', ng-controller='postCtrl') form(method='post') button(ng-click='test()') Click to test Button 发布脚本 var angular = require('angular'); var app = angular.module('postModule', []); app.controller('postCtrl', function ($scope, $sce) { $scope.test = function(){ alert("Working"); }; });