Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法读取属性id ember routes_Javascript_Ember.js - Fatal编程技术网

Javascript 无法读取属性id ember routes

Javascript 无法读取属性id ember routes,javascript,ember.js,Javascript,Ember.js,这就是我的问题,我已经为搜索创建了一个路由,到目前为止,创建一个新的搜索是可行的,我可以提交,它会向后端发送一个rest请求,等等,这样就行了 现在,当我尝试显示我保存的一个时,我得到了这个错误 Assertion failed: Error while loading route: TypeError: Cannot read property 'id' of undefined 我不能再进一步了,因为它不会呈现页面(我知道基本上没有呈现,但我对它进行了注释,以确定这是否是问题所在,不是问

这就是我的问题,我已经为搜索创建了一个路由,到目前为止,创建一个新的搜索是可行的,我可以提交,它会向后端发送一个rest请求,等等,这样就行了

现在,当我尝试显示我保存的一个时,我得到了这个错误

Assertion failed: Error while loading route: TypeError: Cannot read property 'id' of undefined 
我不能再进一步了,因为它不会呈现页面(我知道基本上没有呈现,但我对它进行了注释,以确定这是否是问题所在,不是问题所在,我仍然得到错误信息)

我从后端返回的JSON配置正确,我可以在ember inspector上看到它,我甚至尝试让后端返回所有搜索,ember inspector存储了很多搜索,我仍然得到相同的错误,这是指向要点的链接

谢谢。

尝试更换:

return this.store.find('Search', params.search_id);

注意搜索中的小写“s”

此外,替换:

{"Searches": [{"id": 11, "name": "adwadwd"}]}
与:

{"searches": [{"id": 11, "name": "adwadwd"}]}
路由名称中也使用小写字母“s”:

this.resource('search.new', {path:'/search/new'});
this.resource('search', {path: '/search/:search_id'})
此外,您向服务器请求一个对象,但返回的是一个数组

完整代码:

App.Router.map(function () {
    this.resource('search.new', {path:'/search/new'});
    this.resource('search', {path: '/search/:search_id'})
});

App.SearchRoute = Ember.Route.extend({
    model: function( params ) {
        return this.store.find('search', params.search_id);
    },
});
JSON:

{"search": {"id": 11, "name": "adwadwd"}}
{"search": {"id": 11, "name": "adwadwd"}}