骨干网执行POST请求而不是PUT请求 [英] Backbone doing POST request instead of PUT request

查看:50
本文介绍了骨干网执行POST请求而不是PUT请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将模型的属性设置为其他属性.保存模型后,Backbone会发出POST请求而不是PUT请求.

I am trying to set a model's attribute to be something different. When I save the model, Backbone issues a POST request instead of a PUT request.

我在另一个Stackoverflow帖子上读到,Backbone使用模型的ID来确定模型是否为新模型.当我 console.log(model)时,模型具有id属性.当我 console.log(model.id)时,它打印出未定义的内容.为什么当我执行 console.log(model)时,模型具有id属性,但是当我执行 console.log(model.id)时,我回来了未定义?

I read on another Stackoverflow post that Backbone uses a model's id to determine if a model is new or not. When I console.log(model), the model has an id attribute. When I console.log(model.id), it prints out undefined. How come when I do a console.log(model), the model has a id attribute, yet when I do console.log(model.id), I get back undefined?

Backbone使用哪种方式来确定模型是否为新模型?而且,我该如何解决该问题?我使用的是骨干风格的东西.

Which way does Backbone use to determine if a model is new or not? And, how can I fix the problem? I am using backbone-tastypie.

推荐答案

您是如何首先创建模型的?需要在模型的数据中指定模型的ID.通常,第一次保存新对象时,它将在服务器响应中返回.设置ID后,Backbone会将其保存为PUT而不是POST.

How did you create the model in the first place? The model's id needs to be specified in the model's data. Usually this would be returned in the server response the first time you save a new object. Once the id is set Backbone will save it with PUT instead of POST.

这篇关于骨干网执行POST请求而不是PUT请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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