ドロップダウンリストの値を設定する際に問題があります。ここで私のコードを貼り付けています。ドロップダウンリストと値
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}}
マークの列には、クラス名の代わりに学生名が必要です。誰でも私を助けることができます。ありがとう。
ありがとう、それは私の問題を解決しました。 – naik3
これは嬉しいことです。 –