操纵ember数据上的有效负载normalizePayload

时间:2014-10-14 12:07:40

标签: date ember.js ember-data

如何操纵normalizePayload中的一个值(无论如何我需要将结果转换为会话)
我需要将start_time和end_time与1000相乘,以便顺利进入attr('date')

  "result": [
    {
      "end_time": 1412687629.42063, 
      "start_time": 1412687629.26851, 
    }, 
   {
      "end_time": 1412688377.15329, 
      "start_time": 1412688377.11507, 
    }, 
...

我目前的代码是:

App.SessionSerializer = DS.ActiveModelSerializer.extend({
    normalizePayload: function(payload) {
        return {
            sessions: payload.result
        };
    }
});

1 个答案:

答案 0 :(得分:0)

对不起,我在你的另一个问题的答案中给了你不好的信息。 normalizePayload方法应直接操作payload哈希:

App.SessionSerializer = DS.ActiveModelSerializer.extend({
    normalizePayload: function(payload) {
        payload.sessions= payload.result;
        delete payload.result;
        delete payload.metadata;
        return payload;
    }  
});