I have a application where we have a survey that we want to add rules and conditions to. As a result I am trying to add values to a JSON object that is returned to the client upon loading. I am using ng-repeat to loop through an array that represents "rules" within this object which also have arrays representing "conditions" that will be displayed as elements of the first array. I am trying to figure out how to represent the new elements that won't have ids until it is submitted to the server and added to the database and still have them represented by the forms generated in angular:
{
"rules": [
{
"ruleId": 1235,
"questionId": 5,
"effect": "show",
"conditions": [
{
"conditionId": 1,
"questionId": 1,
"operator": "==",
"value": 2
},
{
"conditionId": 2,
"questionId": 2,
"operator": "~=",
"value": "Hide me"
}
]
},
{
}
]
}
The following data is rendered in the html like this:
<div ng-repeat="rule in survey.rules" class="rule">
<!-- Display the form for modifying data of rule -->
<div ng-repeat="condition in rule.condition">
<!-- The condition details -->
</div>
<a ng-click="survey.addCondition(rule)>(+) Add Condition</a>
</div>
<a ng-click="survey.addRule()>(+) Add Rule</a>
I created a way to add to the array for rules and their array of conditions but when I try to add more than one I get an id conflict since the app is using ruleId and conditionId for indexing. I don't want to assign random ids to the application's data without having an actual id but there may be a better way I can do this so I can pass them to the server and have them save in the database.