javascript - How does angularjs query the second-level menu based on the first-level menu?
伊谢尔伦2017-07-07 10:34:54
0
4
1654
Query the secondary industry through the primary industry, and query the primary industry through the secondary industry. How to write it? The data transmitted in the background is like this
When selecting the first level, send a request to the background to obtain the second level data, and then bind the corresponding data to the second level
My first feeling is that there is something wrong with the data returned by the background. Your secondary menu type field currently seems to be a string, but logically it should be an array, because otherwise, you can directly bind the type_directory field in the corresponding obj to the display box of the primary menu. , and the display box of the secondary menu is just bound to the type field. But obviously it shouldn’t be like this. Thinking: According to your interface data, it should be that when the page is loaded, you have already requested the interface to obtain data (or request data again when clicking the first-level menu box, as long as you give it to the user (Confidence in the experience), at this time, bind all type_directory fields to the drop-down box of the display box of the first-level menu, and then when clicking to select the first-level menu, request data again and obtain the selected first-level menu. The drop-down box where the menu is locatedsubscript, get the type field based on the subscript, and then bind it to the drop-down box of the secondary menu display box It's a bit messy to say it directly, I hope you can understand, in fact, it feels the best, The backend of the first-level menu can give you an ID, and to get the second-level menu, you can directly request the interface to pass the ID, and just pull all the second-level menus under the ID directly
The data must be in cascade form. The first-level menu selects an item, and the sub-level array under the item is assigned to the second-level menu. And so on
When selecting the first level, the change time is triggered and the data bound to the second level is replaced.
When selecting the first level, send a request to the background to obtain the second level data, and then bind the corresponding data to the second level
My first feeling is that there is something wrong with the data returned by the background.
Your secondary menu type field currently seems to be a string, but logically it should be an array, because otherwise, you can directly bind the type_directory field in the corresponding obj to the display box of the primary menu. , and the display box of the secondary menu is just bound to the type field.
But obviously it shouldn’t be like this.
Thinking:
According to your interface data, it should be that when the page is loaded, you have already requested the interface to obtain data (or request data again when clicking the first-level menu box, as long as you give it to the user (Confidence in the experience), at this time, bind all type_directory fields to the drop-down box of the display box of the first-level menu, and then when clicking to select the first-level menu, request data again and obtain the selected first-level menu. The drop-down box where the menu is locatedsubscript, get the type field based on the subscript, and then bind it to the drop-down box of the secondary menu display box
It's a bit messy to say it directly, I hope you can understand, in fact, it feels the best, The backend of the first-level menu can give you an ID, and to get the second-level menu, you can directly request the interface to pass the ID, and just pull all the second-level menus under the ID directly
The data must be in cascade form. The first-level menu selects an item, and the sub-level array under the item is assigned to the second-level menu. And so on