How to pass a list from Python, by Jinja2 to JavaScript

后端 未结 6 1674
挽巷
挽巷 2020-11-27 10:21

Let\'s say I have a Python variable:

list_of_items = [\'1\',\'2\',\'3\',\'4\',\'5\']

and I pass it to Jinja by rendering HTML, and I also h

6条回答
  •  青春惊慌失措
    2020-11-27 11:04

    Make some invisible HTML tags like

    , etc. and name its id, and the class name is a pattern so that you can retrieve it later.

    Let you have two lists maintenance_next[] and maintenance_block_time[] of the same length, and you want to pass these two list's data to javascript using the flask. So you take some invisible label tag and set its tag name is a pattern of list's index and set its class name as value at index.

    {% for i in range(maintenance_next|length): %}
    
    
    {% endfor%}

    Now you can retrieve the data in javascript using some javascript operation like below -

提交回复
热议问题