gpt4 book ai didi

javascript - 加载路线时 ember-data 错误 : TypeError {}

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

我最近开始在我的项目中实现 ember 数据库,但现在一切都坏了,google chrome 控制台向我提供了以下错误:

- Error while loading route: TypeError {} 
- Uncaught TypeError: Cannot read property 'id' of undefined
- Port: Could not establish connection. Receiving end does not exist.

我尝试打开的网址是:/#/track/85

这是相关代码:

Shoutzor = Ember.Application.create();
Shoutzor.ApplicationAdapter = DS.RESTAdapter.extend({
namespace: '/api/emberstore',
host: 'http://www.shoutzor.nl'
});

var attr = DS.attr,
hasMany = DS.hasMany,
belongsTo = DS.belongsTo;

Shoutzor.Track = DS.Model.extend({
id: attr('number'),
title: attr('string'),
//length: attr('number'),
//artist: hasMany('artist'),
//album: hasMany('album'),

/* Convert the length in seconds to a string like '01:55' */
convertedLength: function() {
var sec_num = parseInt(this.get('length'), 10); // don't forget the second parm
var hours = Math.floor(sec_num / 3600);
var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
var seconds = sec_num - (hours * 3600) - (minutes * 60);

if (hours < 10 && hours > 0) {hours = "0"+hours;}
if (minutes < 10 && minutes > 0) {minutes = "0"+minutes;}
if (seconds < 10) {seconds = "0"+seconds;}
var time = ((hours != 0) ? hours + ':' : '') + ((minutes != 0) ? minutes +':' : '') + seconds;

return time;
}.property('length')
});

Shoutzor.Album = DS.Model.extend({
id: attr('number'),
artist: belongsTo('artist'),
title: attr('string'),
cover: attr('string')
});

Shoutzor.Artist = DS.Model.extend({
id: attr('number'),
name: attr('string'),
profileimage: attr('string')
});

Shoutzor.Router.map(function() {
//Track Page
this.route("track", { path: "/track/:id" });
});

Shoutzor.TrackRoute = Ember.Route.extend({
setupController: function(controller) {
controller.set('pageTitle', "Track");
},

renderTemplate: function() {
this.render('TrackContent', { outlet: 'pageContent', into: 'application' });
},

model: function(params) {
return this.store.find('track', params.id);
}
});

Shoutzor.TrackController = Ember.Controller.extend();

Shoutzor.TrackView = Ember.View.extend();

我的 API 提供如下响应:

{"tracks":{"id":85,"title":"Untitled","file":{"filename":"Lines of Latitude - You want it (Free Download).mp3","filepath":"\/home\/vhosts\/domains\/shoutzor\/music\/Lines of Latitude - You want it (Free Download).mp3","crc":"51ca8346","length":262,"id3":[]},"artist":[],"album":[]}}

我一直在查看多个 SO 帖子和谷歌搜索结果,但这些都没有解决我的问题(或者我正在寻找错误的东西),

非常感谢任何帮助!

最佳答案

您不需要在模型类中包含id: DS.attr()。此外,单个资源的响应应具有根键 track 而不是 tracks:

{"track":{"id":85,"title":"Untitled","file":{"filename":"Lines of Latitude - You want it (Free Download).mp3","filepath":"\/home\/vhosts\/domains\/shoutzor\/music\/Lines of Latitude - You want it (Free Download).mp3","crc":"51ca8346","length":262,"id3":[]},"artist":[],"album":[]}}`

关于javascript - 加载路线时 ember-data 错误 : TypeError {},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19426833/

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