0

私はjsonとnode.jsを含む大学のコースの割り当てに取り組んでいます。エラーが発生しましたが、何が間違っているのか理解できないようです。

エラーは次のとおりです。

/home/ubuntu/node_stuff/node_json2/requestHandlers.js:22
'<li>'appts.appointments.appt1.busName'</li>'+
      ^^^^^
SyntaxError: Unexpected identifier
at Module._compile (module.js:437:25)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/home/ubuntu/node_stuff/node_json2/index.js:3:23)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)

これが私が扱っているファイルです:

appts.js

module.exports = {appointments: {
debug: "on",
appt1: {
    busName: "Asheville Eye Associates",
address: {
    street: "8 Medical Park Drive",
    city: "Asheville",
    state: "NC",
    zip: "28803"
},
phone: "828-258-1586",
apptDate: "October 5 2012",
dotw: "Friday",
apptTime: "9:00 am"
},
appt2: {
    busName: "Asheville Dental Care",
    address: {
            street: "10 Yorkshire Street",
            city: "Asheville",
            state: "NC",
            zip: "28803"
    },
    phone: "828-274-3882",
    apptDate: "October 22 2012",
dotw: "Monday",
    apptTime: "10:30 am"
},
appt3: {
    busName: "Asheville Cardiology",
    address: {
            street: "5 Vanderbilt Park Drive",
            city: "Asheville",
            state: "NC",
            zip: "28803"
    },
    phone: "828-274-6000",
    apptDate: "November 14 2012",
dotw: "Wednesday",
    apptTime: "9:30 am"
},

}};

requestHandlers.js

var querystring = require("querystring"),
appts = require("./appts"),
fs = require("fs");

function home(response, postData) {
console.log("Appointments have been parsed from JSON");
console.log("Request handler 'start' was called.");
console.log("stringify appts");
appts = JSON.stringify(appts);
console.log("parse appts");
appts = JSON.parse(appts);
console.log(appts.appointments);

var body = '<html>'+
'<head>'+
'<meta http-equiv="Content-Type" '+
'content="text/html; charset=UTF-8" />'+
'</head>'+
'<body>'+
'<h1>Appointment 1</h1>'+
'<ul>'+
    '<li>'appts.appointments.appt1.busName'</li>'+
    '<li>'appts.appointments.appt1.address.street'</li>'+
    '<li>'appts.appointments.appt1.address.city + " " + appts.appointments.appt1.address.state + " " + appts.appointments.appt1.address.zip'</li>'+
    '<li>'appts.appointments.appt1.phone'</li>'+
    '<li>'appts.appointments.appt1.apptDate'</li>'+
    '<li>'appts.appointments.appt1.dotw</li>'+
    '<li>'appts.appointments.appt1.apptTime'</li>'+    
'</ul>'+
'<h1>Appointment 2</h1>'+
'<ul>'+
    '<li>'appts.appointments.appt2.busName'</li>'+
    '<li>'appts.appointments.appt2.address.street'</li>'+
    '<li>'appts.appointments.appt2.address.city + " " + appts.appointments.appt2.address.state + " " + appts.appointments.appt2.address.zip'</li>'+
    '<li>'appts.appointments.appt2.phone'</li>'+
    '<li>'appts.appointments.appt2.apptDate'</li>'+
    '<li>'appts.appointments.appt2.dotw'</li>'+
    '<li>'appts.appointments.appt2.apptTime'</li>'+
'</ul>'+
'<h1>Appointment 3</h1>'+
'<ul>'+
    '<li>'appts.appointments.appt3.busName'</li>'+
    '<li>'appts.appointments.appt3.address.street'</li>'+
    '<li>'appts.appointments.appt3.address.city + " " + appts.appointments.appt3.address.state + " " + appts.appointments.appt3.address.zip'</li>'+
    '<li>'appts.appointments.appt3.phone'</li>'+
    '<li>'appts.appointments.appt3.apptDate'</li>'+
    '<li>'appts.appointments.appt3.dotw'</li>'+
    '<li>'appts.appointments.appt3.apptTime'</li>'+
'</ul>'+
'</body>'+
'</html>';

response.writeHead(200, {"Content-Type": "text/html"});
response.write(body);
response.end();
}

exports.home = home;

私の問題は単純なものだと確信していますが、別のファイルからオブジェクトをプルするのはこれが初めてです。皆さんが提供できるどんな助けにも感謝します、ありがとう。

4

1 に答える 1

2

演算子を忘れました(おそらく+'<li>')。ただし、コードを自分で作成する代わりに、テンプレートエンジンを使用することをお勧めします。

于 2012-10-02T18:46:17.890 に答える