简体   繁体   English

从骨架.js集合中获取model.id会使用Tastypie创建成功调用吗?

[英]Getting model.id from backbone.js collection create success call using Tastypie?

I used to be able to get my model.id from a newly created backbone collection.create call via the following example code: 我曾经能够通过以下示例代码从新创建的主干collection.create调用中获取model.id:

OPTS['success'] = function( response, model, options ){
                model.id
}

SOMECOLLECTION.create(json_attributes,OPTS)

This no longer works in v1.1.2. 这在v1.1.2中不再起作用。 Anyone know what is going on here? 有人知道这是怎么回事吗? It now returns an array of objects. 现在,它返回一个对象数组。 I am using Django-Tastypie to create my RESTful urls. 我正在使用Django-Tastypie创建我的RESTful URL。

I actually found the problem today, it was I was using namespaces with the tastypie urls: 我今天实际上发现了问题,那是我在使用带有好吃的网址的名称空间:

urlpatterns += patterns('', (r'^api/', include(v1_api.urls)))

was changed to this 改成了这个

urlpatterns += patterns('', (r'^api/', include(v1_api.urls),namespace='api'))

for unit testing purposes, but this created an issue with reverse calls in the tastypie framework itself, and in the end it changed the response.location header to not include the url to the actual model itself after the create (POST) call was made. 出于单元测试的目的,但是这在asteapie框架本身中造成了反向调用的问题,最后,它更改了response.location标头,使其在进行创建(POST)调用后不包含实际模型本身的url。 Remove the namespace fixed this problem 删除名称空间可解决此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM