extjs4 - 是否有用于代理的非 json/xml 编写器?
我正在构建一些模型来与之前项目中的现有 API 进行交互。
API 依赖标准 POST 方法来保存数据。
我已经配置了一个模型和代理,直到它确实将数据推送到服务器上,但似乎只有两种编写器类型:json 和 json。 xml。
proxy: {
/* ... */
reader: {
type: 'json',
root: 'results'
},
writer: {
type: '???' // <-- can only see json or xml in the docs
}
}
是否有一个标准的 POST 编写器可以简单地在 post 字段中提交数据?
我很惊讶这不是标准的作家类型。
(解析 json 格式不会太难实现,但这意味着更新大量旧的 api 文件。)
I'm building some models to interact with an existing API from a previous project.
The API relies on standard POST methods to save the data.
I've configured a model and proxy up to the point where it does push the data onto the server but there only seems to be two writer types, json & xml.
proxy: {
/* ... */
reader: {
type: 'json',
root: 'results'
},
writer: {
type: '???' // <-- can only see json or xml in the docs
}
}
Isn't there a standard POST writer that simply submits data in post fields?
I'm surprised that wouldn't be a standard writer type.
(Parsing the json format wouldn't be too hard to implement but that would mean updating a lot of the old api files.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好的,通过检查现有编写器的源代码,我可以很轻松地创建该编写器。
这些现有的编写者能够做的一件事是他们可以一次推送多个记录,这可能就是开发团队只实现 json 和 xml 版本的原因。
这可以在 POST 中实现,但会稍微复杂一些。
如果您尝试使用 POST 将单个模型推送到 api,则此编写器将起作用:
并在代理中将其用于编写器:
Ok, I was able to create that writer quite easily by checking the existing writers' source code.
One thing those existing writers are able to do - and that may be why the dev team only implemented a json and xml version - is that they can push multiple records at once.
That could be implemented in POST but would be a bit more complicated.
This writer will work if you're trying to push a single model to an api using POST:
and the use this for the writer in the proxy:
根据 Ben 的回答,我已经实现了自己的编写器,它将所有模型的所有属性收集到数组中。
例如,如果您有一些字段的模型:
请求字符串将是
代码:
Based on Ben answer I've implemented my own writer that will collect all properties of all models into arrays.
For example if you have model like with some fields:
A request string will be
Code:
对于 Sencha touch 2.0,将 writeRecords 方法更改为:
For Sencha touch 2.0, change the writeRecords method to:
这是我的版本,改编自上面的答案:
Here's my version, adapted from answers above: