简体   繁体   English

级联下拉列表显示字典/数组

[英]cascading dropdown shows dictionary/array

For my project i need a cascading dropdown. 对于我的项目,我需要一个级联的下拉菜单。 I used the example from here https://jsfiddle.net/mplungjan/65Q9L/ 我从这里使用示例https://jsfiddle.net/mplungjan/65Q9L/

great example and it worked,... half i keep getting my data as sort af an array 很好的例子,它奏效了,...一半我一直在按数组排序来获取数据

[('TEST HEALTCARE',), ('TEST HEALTCARE2',), ('Test healtcare',)]

same goes for the second and third select option. 第二和第三选择选项也是如此。

I'm using flask with jinja and the data comes from an sqlite database 我使用的是Jinja的烧瓶,数据来自sqlite数据库

any idea on how i can get a list with the values instead of the array ? 关于如何获取具有值而不是数组的列表的任何想法吗?

thx !! 谢谢 !!

UPDATE : 更新:

I found a way to return a JSON type list trough this snippet 我找到了一种通过此片段返回JSON类型列表的方法

 var keyValueData = {{ keyValueProjects|tojson }}
         //console.log(keyValueData);

    var result = JSON.parse(keyValueData);
    var healthcare = {};

but the result is I get a error 但结果是我得到一个错误

VM1384:1 Uncaught SyntaxError: Unexpected token o in JSON at position 1

this is my output: 这是我的输出:

var keyValueData = {"TEST ENTERPRISE": ["SubEnterprise 1"], "test Enterprise": ["subEnterprise"]}
         //console.log(keyValueData);

    var result = JSON.parse(keyValueData);
    var healthcare = [];

From what I understand I think it has to do with the "{" at the beginning of the JSON. 据我了解,我认为它与JSON开头的“ {”有关。 any idea on how i can get rid of this. 关于如何摆脱这一点的任何想法。 Or do I miss something. 还是我错过了什么。

thxx! thxx!

You do not need to parse the object as it is already parsed. 您不需要解析对象,因为它已经被解析。

simply use the 只需使用

keyValueData object. keyValueData对象。

like below 像下面

var keyValueData = {{ keyValueProjects|tojson }}     
    var result = *keyValueData* 
    var healthcare = {};

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

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