Javascript 余烬数据类型适配器不工作
我计划很快创建一个由我的TastypieAPI提供服务的ember.js应用程序,目前我正试图进入ember,但我被卡住了 我在教程视频中用fixture数据创建的ember应用程序运行良好,但现在我正在尝试从fixture切换到API,这就是我的问题开始的地方: 这是我想为这个简短测试显示的django模型:Javascript 余烬数据类型适配器不工作,javascript,django,ember.js,tastypie,Javascript,Django,Ember.js,Tastypie,我计划很快创建一个由我的TastypieAPI提供服务的ember.js应用程序,目前我正试图进入ember,但我被卡住了 我在教程视频中用fixture数据创建的ember应用程序运行良好,但现在我正在尝试从fixture切换到API,这就是我的问题开始的地方: 这是我想为这个简短测试显示的django模型: class New(models.Model): date = models.DateField("Erstellt am", auto_created=True, auto_now_a
class New(models.Model):
date = models.DateField("Erstellt am", auto_created=True, auto_now_add=True)
title = models.CharField("Titel", max_length=250)
content = models.TextField("Inhalt")
def __unicode__(self):
return self.title + ', ' + self.date.strftime('%d.%m.%Y')
这是我的模型资源:
class NewResource(ModelResource):
class Meta:
queryset = New.objects.all()
resource_name = 'new'
always_return_data = True
def determine_format(self, request):
return 'application/json'
这是我开门时得到的http://127.0.0.1:8000/v1/new/:
这是我的app.js文件:
App = Ember.Application.create();
App.Router.map(function() {
this.resource('news');
});
App.store = DS.Store.create({
revision: 7,
adapter: DS.DjangoTastypieadapter.extend({
serverDomain: "http://127.0.0.1:8000",
namespace: "v1"
})
});
App.New = DS.Model.extend({
date: DS.attr('string'),
title: DS.attr('string'),
content: DS.attr('string'),
});
App.NewsRoute = Ember.Route.extend({
model: function() {
var news = App.New.find()
return news;
}
});
这是我的车把:
<script type="text/x-handlebars" id="news">
<div class="row">
<div class="col-md-2">
{{#each}}
{{#link-to 'new' this}}
{{title}} // {{date}}
{{/link-to}}
<hr>
{{/each}}
</div>
<div class="col-md-10">
{{outlet}}
</div>
</div>
正如我所说,fixture数据的形式与我从API获得的JSON对象相同,但这样做时没有显示任何内容。我的index.html中包含了ember data tastypie适配器文件。有人能帮我吗?我相信你遇到了与我相同的问题-JSON Django是从不同的源主机名+端口提供的,而不是ember应用程序。我代理了API请求,所以origin保持不变。您可能会尝试更改Access Control Allow Origin标头,看看是否有效。感谢您的回复!但我想我已经放弃了。。
<script type="text/x-handlebars" id="news">
<div class="row">
<div class="col-md-2">
{{#each}}
{{#link-to 'new' this}}
{{title}} // {{date}}
{{/link-to}}
<hr>
{{/each}}
</div>
<div class="col-md-10">
{{outlet}}
</div>
</div>