从Backbone.js的集合入门model.id使用Tastypie创造佳绩电话? [英] Getting model.id from backbone.js collection create success call using Tastypie?

查看:113
本文介绍了从Backbone.js的集合入门model.id使用Tastypie创造佳绩电话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前可以通过下面的例子中code,以获得一个新创建的骨干collection.create打电话给我model.id:

I used to be able to get my model.id from a newly created backbone collection.create call via the following example code:

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

SOMECOLLECTION.create(json_attributes,OPTS)

这不再V1.1.2工作。任何人都知道是怎么回事呢?现在返回对象的数组。我使用的Django Tastypie创建我的REST风格的URL。

This no longer works in 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.

推荐答案

其实,我发现这个问题的今天,这是我使用的命名空间与tastypie网址:

I actually found the problem today, it was I was using namespaces with the tastypie urls:

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

改变为这

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

单元测试的目的,但是这造成的问题与在tastypie框架本身反向调用,并且最终它改变了response.location头不包括创建(POST)调用后的URL实际模型本身被做了。删除修复了这个问题的命名空间。

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. Remove the namespace fixed this problem

这篇关于从Backbone.js的集合入门model.id使用Tastypie创造佳绩电话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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