无法在javascript中定义两个var

时间:2016-04-22 01:23:34

标签: javascript flask

我想在我的javascript代码中定义两个或更多var,但是当我定义第二个时,第一个变为无效。我已经搜索了这个问题,但我不知道为什么。任何人都可以告诉我如何处理这个问题? 这是我的javascript代码(它用于将JSON转换为HTML表格):

<script type="text/javascript">
         var v_first = {{ pass_kegg|safe }}
         var v_seconde = {{ pass_tmp|safe }}

         function buildHtmlTable(myList) {
            //Builds the HTML Table out of myList json data from Ivy restful service.
         }

         function addAllColumnHeaders(myList)
         {
             //Adds a header row to the table and returns the set of columns.Need to do union of keys from all records as some records may not containall records
         }
    </script>

当我只定义一个变量时,一切正常。但是,当我对第二个变量v_second做好准备时,第一个变量v_first将变为无效。

2 个答案:

答案 0 :(得分:1)

似乎你应该使用tojson() filter来生成动态JavaScript,即

<http_header>
  <try>CONNECT www.tutorial</try>
  <method>
    <try>CONNECT www.tutorial</try>
    <success> www.tutorialspoint.</success>
    <attributes>[[C, O, N, N, E, C, T]]</attributes>
  </method>
  <uri>
    <try>www.tutorialspoint.c</try>
    <success> HTTP/1.1\r\nUser-Agen</success>
    <attributes>[[w, w, w, ., t, u, t, o, r, i, a, l, s, p, o, i, n, t, ., c, o, m]]</attributes>
  </uri>
  <http_ver>
    <try>HTTP/1.1\r\nUser-Agent</try>
    <success>\r\nUser-Agent: Mozill</success>
    <attributes>[[1, ., 1]]</attributes>
  </http_ver>
  <fields>
    <try>User-Agent: Mozilla/</try>
    <success></success>
    <attributes>[[[[U, s, e, r, -, A, g, e, n, t], [M, o, z, i, l, l, a, /, 4, ., 0,  , (, c, o, m, p, a, t, i, b, l, e, ;,  , M, S, I, E, 5, ., 0, 1, ;,  , W, i, n, d, o, w, s,  , N, T, )]]]]</attributes>
  </fields>
  <success></success>
  <attributes>[[[C, O, N, N, E, C, T], [w, w, w, ., t, u, t, o, r, i, a, l, s, p, o, i, n, t, ., c, o, m], [1, ., 1], [[[U, s, e, r, -, A, g, e, n, t], [M, o, z, i, l, l, a, /, 4, ., 0,  , (, c, o, m, p, a, t, i, b, l, e, ;,  , M, S, I, E, 5, ., 0, 1, ;,  , W, i, n, d, o, w, s,  , N, T, )]]]]]</attributes>
</http_header>

使用分号终止表达式是一个好习惯,但绝对不是必需。见What are the rules for JavaScript's automatic semicolon insertion (ASI)?

答案 1 :(得分:-1)

试试这个

     var v_first = { pass_kegg|safe };
     var v_seconde = {pass_tmp|safe };

而不是

     var v_first = {{ pass_kegg|safe }}
     var v_seconde = {{ pass_tmp|safe }}

这可能不是100%就可以了