Emberjs - 模型在发送PUT请求时不更改布尔值

时间:2017-04-11 13:26:16

标签: ember.js

早上好!!

在模型上发送更改的boolen值时,我们遇到了请求问题。

从服务器加载模型时,模型中的值为false,但是,当将boolean更新为true值时,请求不会发送true,而是发送false。

路由器:

actions: {
    save:function() {
      let post = this.controller.get("model");
      console.log(post.get("isPost")); // logs **true**
      post.save().then(() => { // request {"description":"The Post","isPost":**false**}
          this.transitionTo('posts');
      }).catch((error) => {
        console.log(error);
      });
    }
}

模型:

import Model from './default';
import DS from 'ember-data';

export default Model.extend({
  description: DS.attr('string'),
  isPost: DS.attr('boolean')
});

我试着在模型上直接将boolean设置为true,但它发送相同的错误请求,发送false而不是true ...

airline.set( 'isPost',TRUE); airline.save ....

1 个答案:

答案 0 :(得分:0)

要为属性设置默认值,请使用以下内容:

isPost: DS.attr('boolean', {defaultValue: false})
相关问题