【发布时间】:2017-06-22 08:11:42
【问题描述】:
我在设置下拉列表的值时遇到问题。我在这里粘贴我的代码。
HTML 代码:
<form ng-submit="save()">
<table style=" table-layout: fixed;" class="table">
<thead>
<tr>
<th>Section</th>
<th>Names</th>
<th>Marks</th>
</tr>
</thead>
<tbody>
<tr>
<td>5th class</td>
<td>
<select id="5thclass" ng-model="setmarks.5thclass" ng-options="val for val in studentname">
<option ng-init="setmarks.5thclass=studentname[0]" selected="selected"></option>
</select>
</td>
<td>
<input type="number" name="5thclass" ng-model="setmarks.marks.5thclass"/>
</td>
</tr>
</tbody>
</table>
<div class="sub" class="btn-group">
<input id="savebutton" type="submit" ng-click="Submit" value="Save" class="btn btn-primary">
</div><br />
</form>
这是我的 angularjs 代码:
$scope.studentname = ["abc","pqr","xyz"];
$scope.save = function(){
$http.post('/savemarks', $scope.setmarks).success(function(data){
console.log("posted data successfully");
console.log( JSON.stringify(data));
}).error(function(data){
console.error("Error posting data");
})
}
最后这是我的 express.js 设置。我将表单详细信息保存到文件的位置。
app.post('/savemarks',urlencodedParser,function(req,res){
fs.appendFile(writecost_file,JSON.stringify(req.body,null,1),function(err){
if(err){
console.log(err);
}else{
console.log("File saved");
}
});
});
输出为json格式:
{"5thclass":"abc","marks":{"5thclass":66}}
我希望输出应该是形式。
{"5thclass":"abc","marks":{"abc":66}}
在标记列中,我想要学生姓名而不是班级名称。谁能帮我 。谢谢 。
【问题讨论】:
标签: javascript angularjs json node.js html