我有一個下拉,基於我創建的jSON對象填充。我正在嘗試將文本值「wineSupplier」傳遞給下拉菜單中的文本選項,但是它將POST中的數組值傳遞給節點。角落傳遞下拉值而不是實際的字符串到節點
因此,如果我的下拉具有以下選項:
- 甲
- 乙
- Ç
d
和我選擇 「C」 的2值是通過,我希望能夠收到「C」
代碼段從wines.ejs:
<form action="/createWine" method="POST">
<p>Select the Wine Supplier:</p>
<select name="wineSupplier" ng-model="supplierSelection" ng-options="supplier as supplier.supName for supplier in suppliers">
</select>
<label>Wine Name:</label>
<input type="text" name="wineName" placeholder="Wine Name"/>
<label>Wine Producer:</label>
<input type="text" name="wineProducer" placeholder="Wine Producer"/>
<label>Wine Colour:</label>
<input type="text" name="wineColour" placeholder="Wine Colour"/>
<label>Wine Type:</label>
<input type="text" name="wineType" placeholder="Wine Type"/>
<label>Wine Country:</label>
<input type="text" name="wineCountry" placeholder="Wine Country"/>
<p>
<button type="submit" class="btn">Submit</button>
</p>
</form>
代碼從app.js
//Create a new wine objhect
app.post('/createWine', function(request, response) {
//create and save a wine model
var wine = new myWine({
wineSupplier: request.body.wineSupplier,
wineName: request.body.wineName,
wineProducer: request.body.wineProducer,
wineColour: request.body.wineColour,
wineType: request.body.wineType,
wineCountry: request.body.wineCountry
});
//save to model
wine.save(function(err, model) {
if (err) {
response.send(504, 'There was an error');
}
else {
response.redirect('/');
}
});
});
乍一看看起來不錯。 「供應商」是什麼樣的? – ryanyuyu 2015-04-03 19:22:25
ng-options =「supplier.supName as supplier.supName for supplier in supplier – 2015-04-03 19:23:10
它是因爲你的值是根據你的代碼設置爲數組供應商的。所以選擇C就是該數組的索引2,這就是爲什麼。 – 2015-04-03 19:24:14