【发布时间】:2014-07-09 02:05:33
【问题描述】:
我很难找到实现此目的的方法。
我正在使用 Node.js、Bootstrap 3 和 express
我想从表单页面开始。当用户填写表单时,他们点击提交。在这里,我想触发一个远程模式。 (通过常规链接或按钮轻松完成此操作。)
这会启动一个帖子。然后如何触发远程模式并将表单数据从帖子传递给它,以便可以在原始表单页面上方的模式窗口中显示带有答案的新远程页面。
这是我的代码:
表格翡翠(cover-form.jade):
html
head
meta(name="viewport" content="width=device-width, initial-scale=1.0")
title= title
link(href="/stylesheets/coverform_custom.css" rel="stylesheet")
body
.modal.fade(id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true")
.modal-dialog.wide-modal
.modal-content
form.form-horizontal(id="coverform" name="coverform" method="post" action="")
.LoginBox.LoginText
fieldset.animated.fadeInUp
// Form Name
legend.LoginText Cover Strategy
// Text input
.form-group
label.col-xs-4.control-label(for='symbol') Stock Ticker:
.col-xs-5
input#symbol.form-control.input-xs(type='text', name='symbol', placeholder='example: AAPL', autofocus, required)
span.help-block Enter Stock Symbol (all capitals)
// Text input
// Select Basic
.form-group
label.col-xs-4.control-label(for='optiondate') Option Date:
.col-xs-5
select#optiondate.form-control(name='optiondate' required)
- for opdate in OptionDates
option(value="#{opdate.OptionDate}") #{moment(opdate.OptionDate).format('dddd, MMMM Do, YYYY')}
span.help-block Date the option closes.
.form-group
label.col-xs-4.control-label(for='strikeprice') Strike Price:
.col-xs-5
input#strikeprice.form-control.input-xs(type='number', name='strikeprice', placeholder='example: 100.00', pattern="[0-9]+([\.|,][0-9]+)?", min="0", step="0.50", required)
span.help-block Strike price of the option.
// Text input
.form-group
label.col-xs-4.control-label(for='optionprice') Option Selling Price:
.col-xs-5
input#optionprice.form-control.input-xs(type='number', name='optionprice', placeholder='example: .45', pattern="[0-9]+([\.|,][0-9]+)?", min="0", step="0.05", required)
span.help-block Price the option is selling for.
// Button
.form-group
label.col-xs-4.control-label(for='submit')
.col-xs-4
button#submit.btn.btn-primary(name='submit' type='submit') Submit
script(src='/javascripts/jquery-2.0.3.min.js')
script(src='/javascripts/bootstrap.min.js')
Remote Modal Jade(尚未引用任何表单数据) answer.jade:
html
body
.modal-header
button(type="button" class="close" data-dismiss="modal" aria-hidden="true")×
h4.modal-title(id="myModalLabel") This Is An Awesome Title
.modal-body
p This Body Is Great
.modal-footer
button.btn.btn-default(data-dismiss="modal") Close
用于路由的 app.js:
...
app.get('/', routes.index);
app.get('/cover', cover.coverForm);
app.post('/cover', cover.doCover);
...
cover.js:
exports.doCover = function(req, res) {
var mystockdata = [];
console.log("Here is the symbol I got: " + req.body.symbol);
StockPrices.find({
Symbol: req.body.symbol
})
.sort('Date')
.exec(function(err, stockdata) {
if (!err) {
stockdata.forEach(function(stockdata) {
mystockdata.push({
"MarketDate": stockdata.Date,
"Open": stockdata.Open,
"High": stockdata.High,
"Close": stockdata.Close,
"Volume": stockdata.Volume
});
});
console.log("Here is the stock Data: " + stockdata);
} else {
console.log(err);
}
res.render('answer', {});
});
};
所以我的问题真的是我如何路由这个,以便在点击 cover-form.jade 上的提交时我可以执行引导模式并使用 doCover 函数触发渲染模式内容的帖子?
也许我也完全错误地处理了这个问题,不知道如何完成我想要的。
非常感谢任何帮助。
【问题讨论】:
标签: html node.js express twitter-bootstrap-3 pug