search

Home  >  Q&A  >  body text

flask - python jinja2 如何从获取javascript function(_index) 传过来的参数 index?

  1. python flask jinja2 如何从获取javascript 传过来的参数

  2. 如下代码

<script>
function itemEdit(_index) {
    console.log("index = " + _index);
    {% set index = _index %}
    var title_name = '{{ datas[index].title_name }}';
    console.log("title_name" + title_name);
    }
</script>

其中的_index 如何赋值给 index ,使得我可以获取datas[index] 这个item
或许我写的不对,但是想要的结果就是如何获取传进来的参数
希望有大神能够解答

迷茫迷茫2786 days ago537

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 10:26:59

    If I understand correctly, you want to write the data directly in the function. You can use the safe filter.

    <script> function itemEdit(_index) {
            console.log("index = " + _index);
            var title_name = {{datas | safe }}[_index].title_name;
            console.log("title_name" + title_name);
        }
    </script>

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 10:26:59

    Make good use of search engines...
    Why Python Flask jQuery AJAX?
    Data interaction between front-end and back-end (jquery ajax+python flask)

    reply
    0
  • Cancelreply