Ember JS, Error while parsing Data in Transformer handeling event `didCommit` in state root.loaded.updated.uncommitted.\"

荒凉一梦 提交于 2019-12-06 03:28:50

As you've figured out ember data doesn't like the use of set in its transforms. Because the server representation of data is often different from how it is represented on the client side. Ember expects transforms to not modify the serialized or deserialized values that are passed in and instead to return new values.

The reason this error is happening is because ember has a state machine to track the state of a record in relation to the server (see http://emberjs.com/api/data/classes/DS.RootState.html). In this case ember is most likely putting the record into the inFlight state. It then calls the transform's serialize function. When item.set is called ember notices a change to the record and inadvertently transitions the record back into the uncommitted state. After the server responds to the save request ember mistakenly assuming the record is still in the inFlight state signals the didCommit event so the record can transition to the saved state. Because the uncommitted state doesn't support the didCommit event ember throws an error.

I suspect you could fix this issue by rewriting your serialize function to not call set and instead to return a new array.

    serialize : function(deserialized) {
        if (Ember.isArray(deserialized)) {
            return deserialized.map(function(item) {
                if (item.get('feldTyp') === "DATE_FIELD" && item.get('value')) {
                    return moment(item.get('value')).format("DD.MM.YYYY");
                }
            });
        }

        return [];
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!