如何使用 Clojure 和 appengine-magic 保存 Text 属性
表单的 body
字段可能包含长文本,因此默认的 String 属性不起作用。
寻找如何使数据存储区使用文本(这不是实体定义的一部分,就像我从 Python 版本中回忆的那样),我在 ackbar 博客的源代码中找到了这一点:
(ns <snip>
(:import (com.google.appengine.api.datastore
EntityNotFoundException Text)))
<snip>
(ds/save! (Post. url title (Text. body) ts in-feed? category))
但如果我这样做,我会得到:“java .lang.RuntimeException: java.lang.IllegalArgumentException: 不知道如何从 com.google.appengine.api.datastore.Text 创建 ISeq”
(一个显着的区别是我正在查看的 ackbar 使用 appengine-magic 0.3.2。)
我还尝试了 https 上简要提到的 as-text
://github.com/gcv/appengine-magic#readme,但其中的 (as-text body)
会导致与上面相同的错误消息。
编辑:事实证明,问题实际上并不是将 Text 属性放入存储中,而是在检索它时理解它。我的提交处理程序触发保存并重新加载表单页面,但我没有想到这一点。抱歉产生噪音。
毫无问题地获取值的方法是(.getValue body)
。
The body
field of a form may contain long text, so the default String property won't do.
Looking for how to make the datastore use Text (this is not part of the entity definition like I recall from the Python version), I found this in the source of the ackbar blog:
(ns <snip>
(:import (com.google.appengine.api.datastore
EntityNotFoundException Text)))
<snip>
(ds/save! (Post. url title (Text. body) ts in-feed? category))
But if I do the same, I get: "java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: com.google.appengine.api.datastore.Text"
(One notable difference is that the ackbar I'm looking at uses appengine-magic 0.3.2.)
I also tried as-text
as briefly mentioned on https://github.com/gcv/appengine-magic#readme, but (as-text body)
in there leads to the same error message as above.
EDIT: Turned out the problem wasn't actually to get a Text property into the store, but to make sense of it when retrieving it. My Submit handler triggers saving and than a reload of the form page, and I failed to think of that. Sorry for the noise.
The way to get the value out without hiccup is (.getValue body)
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 appengine-magic 文档:
因此,您应该将
java.lang.String
传递给as-text
。From the appengine-magic documentation:
So you should pass a
java.lang.String
toas-text
.