开发者

Google App Engine "Multiline" and JavaScript array problem

开发者 https://www.devze.com 2023-02-03 21:15 出处:网络
How do I convert HTML textarea (multiline) to support db.StringProperty() (without the multiline)? I have try string.replace(\"\\n\", \"<br>\") but the problem is when I insert this to javascri

How do I convert HTML textarea (multiline) to support db.StringProperty() (without the multiline)?

I have try string.replace("\n", "<br>") but the problem is when I insert this to javascript ar开发者_Go百科ray it give me problem.

My code as following:

class Anything(db.Model):
 Str_A = db.StringProperty()
...

anything = Anything.all()

template_values = { 'anything ': anything }
path = os.path.join(os.path.dirname(__file__), 'main.html')
self.response.out.write(template.render(path, template_values))

In the Javascript

var Str_A = [];
{% for a in anything %}
 Str_A.push("{{ anything.Str_A }}");  /* This line problem */
{% endfor %}


You could use db.TextProperty() which supports multi-line text by default, or db.StringProperty(multiline=True) if you need to search or sort on the Str_A property (db.TextProperty is not indexed).

0

精彩评论

暂无评论...
验证码 换一张
取 消