2016-09-13 32 views
0

這是我的表格。如何查詢書架而不獲取列的名稱

CREATE TABLE `information_yourself` (
    `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 
    `title` varchar(255) NOT NULL DEFAULT '', 
    `body` text, 
    PRIMARY KEY (`id`) 

INSERT INTO `information_yourself` (`id`, `title`, `body`) 
VALUES 
    (1, 'test1', 'content1'); 
    (2, 'test2', 'content2'); 
    (3, 'test3', 'content3'); 
    (4, 'test4', 'content4'); 

這是利用節點模塊書架

router.get('/', function(req, res){ 
information.where({id:1}) 
.fetch({ columns: ['body'] }) 
.then(function(model){ 
    var obj = JSON.stringify(model); 
    var str = obj.replace(/[\[\]\{\}]+/g, ''); 
    res.render('test.ejs', {str}); 
}) 

})

結果是 ' 「體」:' 我的查詢內容1' 。

我如何收到結果'內容1'而沒有結果檢索列名?

任何幫助將不勝感激。

回答

0

試圖修改此行

var obj = JSON.stringify(model); 

var obj = JSON.stringify(model['body']); 

這可能會有所幫助!