0

I am trying to design the data model for

-> Section
   -> Sub Section
      ->Main Element
      ->Main Element
   -> Sub Section
      ->Main Element
      ->Main Element
      ->Main Element
...

This is what I have right now:

[{
  'section': 'market map',
  'subsections': ['aa','bb'],
  'mainelements': 
      [
        ['cc','dd'],
        ['ee','ff'],
      ]
}];

This is what I want:

-> Market Map
   -> aa
      ->cc
      ->dd
   -> bb
      ->ee
      ->ff

This is my html:

<ul>
        <li ng-repeat="data in datas">
                <ul>
                <li ng-repeat="subsection in data.subsections">
                       <input type="text" ng-model="subsection"  size="30" placeholder="add subsection here">
                       <ul>
                        <li ng-repeat="mainelement in audit.mainelements">
                            <input type="text" ng-model="mainelement"  size="30" placeholder="add mainelement here">
                        </li>
                       </ul>
                </li>
                </ul>
         </li>
</ul>

and i get this:

-> Market Map
   -> aa
      ->[cc, dd]
   -> bb
      ->[ee, ff]
  1. How can I get the result I wanted?
  2. Is there a better way to design the json structure for this kind of hierarchy?

1 Answer 1

2

Make your json design like this

$scope.datas=[{
  'section': 'market map',
  'subsections': [{
      subSection: 'aa',
      mainelements: ['cc','dd']
   },{
     subSection: 'bb',
     mainelements: ['ee','ff']
   }]
}];

Then your html will be

<ul>
        <li ng-repeat="data in datas=">
            {{data.section}}
                <ul>
                <li ng-repeat="subsection in data.subsections">
                       <input type="text" ng-model="subsection.subsection"  size="30" placeholder="add subsection here">
                       <ul>
                        <li ng-repeat="mainelement in subsection.mainelements">
                            <input type="text" ng-model="mainelement"  size="30" placeholder="add mainelement here">
                        </li>
                       </ul>
                </li>
                </ul>
         </li>
</ul>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.