我需要从.hbs文件中的此代码块中检索选定的下拉列值...
<div class="section-color">
<div class="jumbotron jumbotron-md center-block">
<h2>{{survey.name}} Cluster</h2>
<p>This cluster was calculated using kmeans with k = {{k}}</p>
<p> Change cluster to: </p>
<select class="form-control" name='kvalue' id="kvalue" value='{{form.kvalue}}'>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
<option value=6>6</option>
<option value=7>7</option>
<option value=8>8</option>
<option value=9>9</option>
<option value=10>10</option>
</select>
<a class='btn btn-default' href='/survey/{{survey._id}}/results'>Clusterize!</a>
</div>
..并将其用作&#39; k&#39;此node.js路由文件中的值:
async function renderViewResults (req, res, next) {
const { id } = req.params;
try {
let { survey, questions } = await fetchSurveyInfo(id);
const responses = await Response.find({ surveyId: survey._id });
const userResponse = responses.filter(res => res.userId.toString() === req.user._id.toString())[0];
const userAnswerSequence = !isNil(userResponse);
if (userResponse) {
questions = questions.sort((a, b) => {
return userResponse.answerSequence.indexOf(a) - userResponse.answerSequence.indexOf(b);
});
}
const k = 4; //where reference should be made to dropdown item
const vectors = kmeans.vectorizeResponses(responses);
const cluster = await kmeans.clusterize({ vectors, k });
任何有关我应如何做到这一点的帮助将不胜感激!
更新 这是我正在进行的项目的一部分,所以我对node / express / javascript的了解是原始的。