使用ember render helper时无法保存模型 [英] Cannot save model when using ember render helper

查看:95
本文介绍了使用ember render helper时无法保存模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  {{renderteacherteacher}} 

这是它的控制器:

  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(' ('model')。save();
}
}
});
this.get

以下是调用此方法时的输出:




Class {isFulfilled:true,toString:function,constructor:function,reason:null,isPending:undefined ...}
true
Uncaught TypeError:Object [object Object]没有方法'save'

这种做法没有我之前遇到的问题。它只是在我使用 render 时发生。



更新



下面是我在Ember Inspector中查看 TeacherController 的屏幕截图:





另一个就是我的查看层次结构:

解决方案

看起来好像该模型是一个PromiseObject(来自异步映射)。 Promise对象是Ember.ObjectProxy的一个扩展,它将把属性调用委托给真实模型(如果它存在的话),但这些方法没有被代理。

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


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:

解决方案

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();
   });

这篇关于使用ember render helper时无法保存模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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