垃圾邮件数据序列化在POST上取消和反序列化 [英] Ember Data serialize on fetch and deserialize on POST

查看:125
本文介绍了垃圾邮件数据序列化在POST上取消和反序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ember数据从远程服务器获取数据。
我的模型定义如下 -

  App.Publisher = DS.Model.extend({
名称:DS.attr('string'),
appName:DS.attr('string'),
url:DS.attr('string'),
appType:DS.attr ('number'),
streamType:DS.attr('number'),
sslEnabled:DS.attr('number'),
protocol:DS.attr('number' ,

});

服务器的响应格式如下 -

  {
id:1,
name:aurus,
url:1111,
app_name: superprofs
app_type:1,
stream_type:1,
ssl_enabled:1,
协议:1,
created_at:2014-08-08T10:52 :40.000Z,
updated_at:0000-00-00 00:00:00
},

但是,由于服务器中的键位于下划线格式和我的模型键是 camelCase
未设置服务器的值。



如何使我的模型键适应服务器发送的数据格式(下划线),然后当我调用save / create / update在ember js中,我希望以下划线格式发送数据,因为我的服务器API期望下划线格式的数据

解决方案

对于那些谁是遇到同样的问题,我使用 ActiveModelAdapter



修正它使我的ApplicationAdpater从DS.ActiveModelAdapter扩展。

  App.ApplicationAdapter = DS.ActiveModelAdapter.extend({}); 


I am using ember data to get data from a remote server. My model definition is as follows -

App.Publisher = DS.Model.extend({
    name: DS.attr('string'),
    appName: DS.attr('string'),
    url: DS.attr('string'),
    appType: DS.attr('number'),
    streamType: DS.attr('number'),
    sslEnabled: DS.attr('number'),
    protocol: DS.attr('number'),

});

And the response from the server is in the following format -

{
  id: 1,
  name: "aurus",
  url: "1111",
  app_name: "superprofs",
  app_type: 1,
  stream_type: 1,
  ssl_enabled: 1,
  protocol: 1,
  created_at: "2014-08-08T10:52:40.000Z",
  updated_at: "0000-00-00 00:00:00"
},

But since the key from server is in underscore format and my model keys are camelCase, the values from the server are not being set.

How can I make my model keys to adapt to the format of data the server is sending(underscore) and then when I call save/create/update in ember js, I want the data to be sent in underscore format, since my server API is expecting the data in the underscore format

解决方案

For the folks who are running into the same problem, I fixed it using ActiveModelAdapter

I made my ApplicationAdpater to extend from DS.ActiveModelAdapter.

App.ApplicationAdapter = DS.ActiveModelAdapter.extend({});

这篇关于垃圾邮件数据序列化在POST上取消和反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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