我在谷歌应用程序引擎Python代码都这样了,GAE +的Javascript推:多推
class ABC(db.Model):
StringA = db.StringProperty()
StringB = db.StringProperty(multiline=True)
abcs = ABC.all()
template_values = {'abcs': abcs,}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
,这在index.html的,
<script type="text/javascript">
var string_A = [];
var string_B = [];
{% for abc in abcs %}
string_A.push("{{ abc.StringA }}");
string_B.push("{{ abc.StringB }}"); //This doesn't work?
{% endfor %}
</script>
我的问题是,如何我推多行到数组??
在此先感谢。
Multiline对Javascript有点棘手,用string_B中的'\'替换'\ n'应该可以工作。 – systempuntoout 2011-01-06 16:19:55
只有替换\ n才能解决换行问题,但会留下其他字符(例如配额标记)和潜在的XSS漏洞。 – ehabkost 2011-01-12 12:35:53