Cannot save model when using ember render helper

你说的曾经没有我的故事 提交于 2019-12-14 01:54:53

问题


I'm rendering a model into a parent template like this:

{{render "teacher" teacher}}

Here's it's controller:

App.TeacherController = Ember.ObjectController.extend(App.EditableModelMixin, {
    actions: {
        saveTypes: function() {
            if (this.get('model')) console.log('Exists');
            console.log(this.get('model'));
            console.log(this.get('model').get('isFulfilled'));
            this.get('model').save();
        }
    }
});

Here's the output when this method is called:

Exists
Class {isFulfilled: true, toString: function, constructor: function, reason: null, isPending: undefined…}
true
Uncaught TypeError: Object [object Object] has no method 'save'

This way of doing things has had no problems for me before. It only seems to happen when I use render.

Update

Here's a screen shot of me looking at the TeacherController in Ember Inspector:

And another of just my view hierarchy:


回答1:


It appears as if that model is a PromiseObject (from an async mapping). Promise objects are an extension of Ember.ObjectProxy which will proxy property calls down to the real model if it exists, but the methods aren't proxied.

   var modelPromise = this.get('model');
   modelPromise.then(function(actualModel){
     actualModel.save();
   });


来源:https://stackoverflow.com/questions/20846408/cannot-save-model-when-using-ember-render-helper

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