简体   繁体   English

反应式下拉

[英]reactive dropdown

I'm new to flask and webdev.我是 flask 和 webdev 的新手。 I cant seem to find any true helpful resources on how to create a reactive dropdown list.我似乎找不到任何关于如何创建反应式下拉列表的真正有用的资源。

I have 2 variables in another file from a textfile I've formatted.我格式化的文本文件中的另一个文件中有 2 个变量。 I want to use them in the webapp.我想在 webapp 中使用它们。 They are [1] first authors and [2] total authors他们是 [1] 第一作者和 [2] 总作者

[1] first authors is a list of authors and it should be the values the dropdown menu will have. [1] 第一作者是作者列表,它应该是下拉菜单将具有的值。

[author1,author2,author3]

[2] total authors is a dictionary where each key is a different first author and the values are the coauthors [2] 总作者是一个字典,其中每个键是不同的第一作者,值是共同作者

author1: [helping authors]
author2: [helping authors]
author3: [helping authors]

I want a dropdown menu that when you choose an author, it will show all coauthors我想要一个下拉菜单,当您选择作者时,它将显示所有共同作者

I've copied some code from here but all I've gotten to show is the dropdown menu that dosen't react我已经从这里复制了一些代码,但我所展示的只是没有反应的下拉菜单

This is entirely a JavaScript thing;这完全是一个 JavaScript 的东西; I am not really familiar with flask but had to do the same thing few month ago with Django and I couldn't really find a better solution than to implement it using Ajax.我对 flask 不是很熟悉,但几个月前不得不用 Django 做同样的事情,我真的找不到比使用 Ajax 实现它更好的解决方案。

If you aren't familiar with Ajax Here is a great place to get you started.如果您不熟悉 Ajax 是一个让您入门的好地方。

This response may also help you.此响应也可能对您有所帮助。

You can also simply use only JavaScript by loading all your data to a template and dealing with your conditions using JavaScript (maybe an event listener 'change' to a form).您也可以仅使用 JavaScript,方法是将所有数据加载到模板并使用 JavaScript 处理您的条件(可能是事件侦听器“更改”为表单)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM