这是一个 zappajs/coffeescript 新手问题,我尝试编写一个从 mysql 收集并使用 div 而不是表呈现结果的脚本,到目前为止只有一行。我的问题如何传递整个结果数组以使用模板输出?下面的代码示例,欢迎任何批评,谢谢:
@post '/', (req, res) -> #POST FOR SHOWSTOCK
MysqlConnection = mysql.createConnection(
...
)
MysqlConnection.connect()
....
else
sql = "select art.artcode,art.artname, art.artsonst, groessen.colcode,groessen.artgrb,groessen.artwidth,groessen.artist,date_format(artoffdate,'%d-%m-%y') as mydate, groessen.soreason from groessen,art where groessen.artcode = art.artcode and art.artcode = " + MysqlConnection.escape(req.body.art.artcode)
MysqlConnection.query sql, (err, rows) ->
throw err if err
...
exports.art = rows
...
MysqlConnection.end
@redirect '/showstock' # 'back' or 'home'= "/"
@get '/': ->
@render index: {
}
@view index: ->
h1 img src: '/BW_AL_Logo_Blue.jpg', align:'left', alt:'Logo' , width:240, height:120, top:25, left:370 ,position:'absolute'
h2 style: "font-family:sans-serif;;position: absolute; top: 10px; width: 250px; left: 350px; height: 25px; background-color: white", 'XYZ Stock Information'
form method: "post", action: "/", ->
div "#Artcode", style: "position: absolute; top:60px; left:680px; width: 121px; height: 21px;", ->
input type: "text", name:"art[artcode]"
div "#Submit", style: "position: absolute; top:60px; left: 840px; width: 121px; height: 21px;", ->
input type: "submit", value: "Submit"
@get '/showstock': ->
@render showstock: {
artname0: exports.art[0].artname
...
}
@view showstock: ->
h1 img src: '/BW_AL_Logo_Blue.jpg', align:'left', alt:'Logo' , width:240, height:120, top:25, left:370 ,position:'absolute'
...
div style: "position: absolute; left: 10px; top: 195px; height: 400px; width:1200px; padding: 2px; border:2px solid gray;",->
div "#colcode", style: "height: 3px;width:90px;float:left;",->
b "COLOUR"
br()
@colcode0
div ...