我试图限制页面中的字符数,所以我有这个
var express = require('express');
var router = express.Router();
var connection = require('../connection');
/* GET home page. */
router.get('/', function(req, res) {
connection.query('SELECT title, LEFT(bode,12) FROM
articles',function(error, results){
if(error) throw error;
console.log(results);
res.render('index',{data: results});
});
});
module.exports = router;
在我的 View 文件中我有这个
<% data.forEach(function(data) { %>
<h1><%= data.title %> </h1>
<p><%= data.bode %></p>
<% }); %>
但是 bode 部分没有显示任何内容,我得到一个控制台日志及其显示正确的数据,但不在我的 html 页面上,当我使用查询的左侧时,我得到整个 bode 部分,但我只想显示10个字符
最佳答案
结果集有 2 列,一列名为 "title"
,一列名为 "LEFT(bode,12)"
,该列不易作为属性访问(你也不想)。
试试这个:
SELECT title, LEFT(bode,12) AS bode FROM articles
关于javascript - 为什么我的 SUBSTRING 或 LEFT SQL 查询不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33713277/