我想制作一些库存的下拉列表。例如,我的数据库中有两个字段
>>> data = '''{"ships":{"2":{"name":"Asp","alive":true,"id":2},"3":{"starsystem":{"systemaddress":"670417429889","id":"670417429889","name":"Diaguandri"},"station":{"id":3223343616,"name":"Ray Gateway"},"name":"SideWinder","alive":true,"id":3},"12":{"starsystem":{"systemaddress":"18263140541865","id":"73228","name":"Barnard's Star"},"station":{"id":128147960,"name":"Miller Depot"},"name":"Viper_MkIV","alive":true,"id":12},"13":{"starsystem":{"systemaddress":"673101653409","id":"673101653409","name":"Brestla"},"station":{"id":3224813312,"name":"Roed Odegaard Port"},"name":"Type7","alive":true,"id":13},"14":{"starsystem":{"systemaddress":"673101653409","id":"673101653409","name":"Brestla"},"station":{"id":3224813312,"name":"Roed Odegaard Port"},"name":"SideWinder","alive":true,"id":14}}}'''
... import json
... data = json.loads(data)
>>> ships = [item['name'] for index, item in data['ships'].items()]
>>> ships
8: [u'Viper_MkIV', u'SideWinder', u'Asp', u'Type7', u'SideWinder']
>>>
因此,当我创建表单时,我将columnA放在下拉列表中,另一个字段是输入类型。
然后我希望在下拉列表中更改我的选择时,在另一个字段中显示更改值。
顺便说一下,我正在寻找Generate Forms Based on user Data。我认为解决方案可能就是这样。
我希望你的帮助。 Grettings
答案 0 :(得分:0)
我建议您在更改第一个下拉列表中的值时触发ajax函数。此函数将与将发出数据库请求的控制器进行交互。最后,在成功之后,您的ajax函数将使用返回值填充第二个下拉列表。