I’m new to ionic and trying to put together an app with nested json that populates an accordion list. So far, I can populate the accordion but I want to have the user click on one of the items that takes them to a details page. The json I am trying to process looks like:
{
"Items": [
{
"Name": "Item 1",
"Number: 1
"Subcategories": [
{
"Name": Sub Item 1"
"Description": "A description about the item..."
}
"Name": Sub Item 2"
"Description": "A description about the item..."
}
}
"Name": Sub Item 3"
"Description": "A description about the item..."
}
}
}
As mentioned, I can populate the accordion list with an ion list with ng-repeat=“item in items” and the expanded accordion with ng-repeat=“name in item.subcategories”.
I am having trouble however in populating the detail page where it would list the name of the sub item along with the description.
Is anyone able to please point me in the right direction? I have tried following a few tutorials but all seem to point to different solutions. I understand I might need to create a ng-click with a call to a controller function but am stuck with exactly what I need to create.
According to your first paragraph,I believe you should check out the stateParams for angular ui-router, it may help you to bring parameters from state to state.
According to your second paragraph, you should not only use “name” after the ng-repeat, you should use name.name. For example:
<div ng-repeat="name in item.subcategories">
{{name}} //this is indeed the whole object
{{name.name}} //this is what you want
{{name.description}} //this is the description
</div>
The problem is that the “xxx in item.subcategories”, the “xxx” here is only an alias for you to call in the following content, so it is just all the single objects that contains both name and description. You can name it in a better way for no further confusion.
The HTML I’ve copied belongs to the tab where I am trying to output the information. The list is in the form of an accordion so I can get:
Item 1
- Sub Item 1
- Sub Item 2
- Sub Item 3
Item 2
- Sub Item 1
- Sub Item 2
- Sub Item 3
I also have an app.js that lists the state of the tab and attempting to display the tab from the details page. Sorry for including this here and not the codepen, I wasn’t sure if I should paste this under the JS frame.
In my onSelectItems function, what should I set the $location.url to? Should it just be the detail html page? I think this is where I may be getting confused.
Alright, I’m a idiot here. I updated to $state.go and can get to my itemDetail page. The next step is actually displaying the subitem description. Do I need to do anything special in my itemDetails page? How do I extend the state to this page?