extjs4 - 是否有一个非json / xml作者代理? [英] extjs4 - is there a non json/xml writer for proxies?

查看:101
本文介绍了extjs4 - 是否有一个非json / xml作者代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



API依赖于标准POST方法来保存数据。

>

我已经配置了一个模型和代理,直到它将数据推送到服务器上,但似乎只有两个写入器类型,json& xml。

  proxy:{
/ * ... * /
reader:{
类型:'json',
root:'results'
},
writer:{
type:'???'//< - 只能看到json或文档中的xml
}
}

没有标准POST作者只需在后期字段中提交数据。



我很惊讶,这不是一个标准的作家类型。



(解析json格式不会太难实现,但这意味着更新很多旧的api文件。)

解决方案

好的,我可以通过检查现有作者的源代码来轻松创建该作者。



现有作家能够做的一件事 - 这可能是开发团队只实现一个json和xml版本的原因 - 他们可以一次推多个记录。



这可以在POST中实现,但会更复杂一些。



如果您尝试将单个模型推送到api,此作者将会工作POST:

  Ext.define('Ext.data.writer.SinglePost',{
extend:'Ext。 data.writer.Writer',
alternateClassName:'Ext.data.SinglePostWriter',
alias:'writer.singlepost',

writeRecords:function(request,data){
request.params = data [0];
返回请求;
}
});

,并将其用于代理作者:

 作者:{
类型:'singlepost'
}


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.)

解决方案

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:

Ext.define('Ext.data.writer.SinglePost', {
    extend: 'Ext.data.writer.Writer',
    alternateClassName: 'Ext.data.SinglePostWriter',
    alias: 'writer.singlepost',

    writeRecords: function(request, data) {
        request.params = data[0];
        return request;
    }
});

and the use this for the writer in the proxy:

writer: {
            type: 'singlepost'
        }

这篇关于extjs4 - 是否有一个非json / xml作者代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆