鍍金池/ 問答/HTML/ express獲取 路徑數(shù)據(jù)

express獲取 路徑數(shù)據(jù)

用express獲取nodejs數(shù)據(jù)時遇到了個問題

數(shù)據(jù)格式

{
    "header": {
        "logo": "assets/img/head_logo.jpg",
        "titleList": [
            {
                "svg": "assets/img/d_home.svg",
                "title": "首頁"
            },
            {
                "svg": "assets/img/d_work.svg",
                "title": "工作"
            }
        ],
        "musicLogo": {
            "src": "assets/img/me_logo.jpg",
            "className": "musicLogo"
        },
    },
    "main": {
    
    }
}

在獲取后臺數(shù)據(jù)時,想用路徑模式的返回數(shù)據(jù) 如:

app.get("/header/titleList", function(req, res) {
    res.send(
        res.header.titleList // 我想從后臺返回這種路徑模式的數(shù)據(jù), 而不是html文件或者假數(shù)據(jù)
    )    
}

但是這樣無法獲取數(shù)據(jù), 請問我應(yīng)該做么做

回答
編輯回答
敢試

你把你那個數(shù)據(jù) exports,
在你取數(shù)據(jù)那個文件 import

2017年10月7日 10:12
編輯回答
失魂人

你用的方法不對,不是用res.send,而是應(yīng)該用res.render('[路徑]', {數(shù)據(jù)})或者用res.json({數(shù)據(jù)}),這樣的方式。

2017年8月8日 20:51