search

Home  >  Q&A  >  body text

Javascript quotation marks issue?

I don’t know how to express the question. Go directly to code

  xAisdata.push("(u'Chunyang', 9)")
        
  xAisdata.push("(u"Fu'an", 505)")#值中的"和外面的"冲突了。
        
  xAisdata.push("(u'Huwei', 250)")
        
  xAisdata.push("(u'Tainan City', 66926)")
        
  xAisdata.push("(u'Dacang', 868)")
        

The value to be added to the array is the value retrieved from the database. Therefore, changing this value may not be practical. How should I handle this situation? Thanks


{% for k,v in data %}
            xAisdata.push("{{ k | safe}}");
{% endfor %}

{% %} is Django’s template syntax

曾经蜡笔没有小新曾经蜡笔没有小新2797 days ago701

reply all(2)I'll reply

  • 阿神

    阿神2017-05-19 10:14:43

    var str = "(u\"Fu'an\", 505)"; 
    
    console.log(str); 

    Use escape characters

    If you don’t bring it when you come out of the database

    It is recommended to use template string

    `(u\"Fu'an\", 505)`

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-19 10:14:43

    Isn’t it okay to assign that (u"Fu'an", 505), (u'Dacang', 868), etc. to a local variable and then push (the variable)?

    reply
    0
  • Cancelreply