Mit meiner JSON-Datei erstelle ich ausgewählte Fragen in meiner Web-App. Der Code, den ich für meine select-Tag haben, ist wie folgt:Tag auswählen, das keine Eingabedaten in korrekter Form zurückgibt (Angular)
<div class="form-group" ng-class="{ 'has-error': form.$submitted && form[field.id].$invalid }" ng-if="field.type === 'select'">
<label for="{{field.id}}">{{field.title}}</label>
<br>
<select ng-model="formData[field.id]" ng-value="{{value.title.id}}" ng-options="value as value.title for value in field.values">
<option disabled selected value> -- select an option -- </option></select>
<p class="form-group-note" ng-if="field.info" ng-bind="field.info"></p>
<div ng-show="form.$submitted" ng-cloack>
<span class="help-block" ng-show="form['{{field.id}}'].$error.required" ng-if="field.validations.required">Please enter a value, this field is required</span>
</div>
</div>
ich eine JSON-Datei wie folgt haben:
{
"groups": [
{
"id": "10_8_group",
"title": "Existence",
"index": 60,
"part": 10,
"sections": [
{
"id": "10_8_section",
"title": "Existence",
"fields": [
{
"id": "10_8_labor_organization",
"title": "8. Does it exist?",
"info": "Always select \"No\"",
"type": "select",
"size": {
"width": 100,
"height": 1
},
"values": [
{
"id": 1,
"title": "Yes"
},
{
"id": 2,
"title": "No. If no, proceed to Part 9. and type or print your explanation."
}
]
}
]
}
]
}
]
}
, wenn die Daten in localstorage (Angular Frontend-Modell) gespeichert wird, es die Daten als "10_8_labor_organization":{"id":1,"title":"Yes"}}
jedoch spart, würde Ich mag diese
"10_8_labor_organization":"Yes"
als
sparen
Wie kann ich das erreichen ??
es value.title als value.title war das ein bisschen komisch scheint aber funktioniert – Kahsn
@Kahsn in „value.id als value.title“ Anweisung „value.id“ arbeitet als Wert Attribut für select option tag und "value.title" funktioniert als Text –