gpt4 book ai didi

ember.js - 添加计算属性时,Ember Data 使用错误的请求方法

转载 作者:行者123 更新时间:2023-12-02 06:09:10 25 4
gpt4 key购买 nike

我对此有详细的观察。不知道我在这里做错了什么。我有一个模型定义,我在其中计算一个 bool 值。导致deleteRecord()使用错误的请求方法发送数据的方法( POST 而不是 DELETE )。当我调用 save() 时它通过 PUT 发送请求的方法而不是 POST
请注意:当我删除计算的属性定义时,代码工作正常。

模型定义

var attr = DS.attr(),
string = DS.attr('string'),
boolean = DS.attr('boolean'),
number = DS.attr('number'),
hasMany = DS.hasMany();

App.Status = DS.Model.extend({
sticky: boolean,
title: string,
date: string,
categories: attr,
content: string,
comment_allowed: boolean,
replying: DS.attr('boolean', {defaultValue: false}),

isNew: function(){
var unix = parseInt( moment(this.get('date')).format('X') );
var current = parseInt(moment().format('X'));
var four_hours = 60 * 60 * 4;
return ( (unix + four_hours) > current);
}.property('date')

});

从 Controller 中删除项目

当我尝试从操作处理程序中删除记录时 destroyRecord()使用 POST 发出 ajax 请求而不是 DELETE .请求网址也是错误的。它被发送到 /statuses而不是 /status/id
App.IndexController = Ember.ArrayController.extend({
actions: {

deleteStatus: function(status_id){

if(!confirm('Are you sure you want to delete this status?'))
return;

this.store.find('status', status_id).then(function(status){
console.log(status);
status.destroyRecord();
});
}
}
});

另请注意,计算的属性函数按预期工作,没有任何错误。

编辑

查找 RESTAdapter 的代码以下。如果我再次注释掉 Computed Property 部分,则代码可以正常工作。
App.ApplicationAdapter = DS.RESTAdapter.extend({
host: config.siteUrl,
namespace: 'wp-json',
headers: {
"X-WP-Nonce": config.nonce
}
});

最佳答案

您不能使用 isNew对于属性名称,因为 ember-data 已经将其用于自己的目的。尝试将属性更改为 isRecent或类似的东西。

关于ember.js - 添加计算属性时,Ember Data 使用错误的请求方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27546649/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com