lch*_*lch 2 javascript ember.js
Router.js
Router.map(function() {
this.route('artists', function() {
this.route('artist', {path: ':id'}, function() {
this.route('songs');
});
});
});
Run Code Online (Sandbox Code Playgroud)
路线/ artists.js
export default Ember.Route.extend({
model(){
return this.store.findAll('artist');
}
});
Run Code Online (Sandbox Code Playgroud)
路线/艺术家/ artist.js
export default Ember.Route.extend({
model(params){
console.log(params.id); //printed a valid id (-KP_nH0EMk3zYqhiWJZ1)
return this.store.findRecord(params.id);
}
});
Run Code Online (Sandbox Code Playgroud)
模板/ artists.hbs
{{#each model as |artist|}}
<li class="list-group-item"> {{#link-to 'artists.artist.songs' artist}} {{artist.name}} {{/link-to}}</li>
{{/each}}
Run Code Online (Sandbox Code Playgroud)
错误
ember.debug.js:28535 Error while processing route: artists.artist.songs Assertion Failed: `id` passed to `findRecord()` has to be non-empty string or number Error: Assertion Failed: `id` passed to `findRecord()` has to be non-empty string or number
at new Error (native)
at Error.EmberError (http://localhost:4200/assets/vendor.js:26708:21)
at assert (http://localhost:4200/assets/vendor.js:16548:13)
at Object.assert (http://localhost:4200/assets/vendor.js:26472:34)
at assert (http://localhost:4200/assets/vendor.js:68333:37)
at Class.findRecord (http://localhost:4200/assets/vendor.js:76157:41)
at Class.model (http://localhost:4200/assets/ember-basics.js:259:22)
at Class.deserialize (http://localhost:4200/assets/vendor.js:37088:19)
at Object.applyHook (http://localhost:4200/assets/vendor.js:63718:30)
at Object.runSharedModelHook (http://localhost:4200/assets/vendor.js:61926:33)logError @ ember.debug.js:28535error @ ember.debug.js:28478triggerEvent @ ember.debug.js:28594trigger @ ember.debug.js:53473trigger @ ember.debug.js:53287(anonymous function) @ ember.debug.js:53107tryCatch @ ember.debug.js:53806invokeCallback @ ember.debug.js:53821publish @ ember.debug.js:53789publishRejection @ ember.debug.js:53724(anonymous function) @ ember.debug.js:32054invoke @ ember.debug.js:333flush @ ember.debug.js:397flush @ ember.debug.js:205end @ ember.debug.js:560run @ ember.debug.js:682run @ ember.debug.js:21139(anonymous function) @ firebase.js:134c @ firebase.js:396(anonymous function) @ firebase.js:387Ub @ firebase.js:283vc @ firebase.js:271wc @ firebase.js:270(anonymous function) @ firebase.js:454(anonymous function) @ firebase.js:427h.wd @ firebase.js:432af.wd @ firebase.js:335(anonymous function) @ firebase.js:333yd @ firebase.js:286La.onmessage @ firebase.js:285
ember.debug.js:32096 Error: Assertion Failed: `id` passed to `findRecord()` has to be non-empty string or number
at new Error (native)
at Error.EmberError (http://localhost:4200/assets/vendor.js:26708:21)
at assert (http://localhost:4200/assets/vendor.js:16548:13)
at Object.assert (http://localhost:4200/assets/vendor.js:26472:34)
at assert (http://localhost:4200/assets/vendor.js:68333:37)
at Class.findRecord (http://localhost:4200/assets/vendor.js:76157:41)
at Class.model (http://localhost:4200/assets/ember-basics.js:259:22)
at Class.deserialize (http://localhost:4200/assets/vendor.js:37088:19)
at Object.applyHook (http://localhost:4200/assets/vendor.js:63718:30)
at Object.runSharedModelHook (http://localhost:4200/assets/vendor.js:61926:33)
Run Code Online (Sandbox Code Playgroud)
导航到"artists/{id}"和"artists/{id}/songs"时,我遇到了这个错误.我尝试在艺术家/艺术家路线上打印params.id.我可以在控制台中看到有效的ID.有人可能会猜出可能存在的错误
findRecord
需要两个强制性参数modelName
和id
,你的情况型号名称缺失.
路线/艺术家/ artist.js
export default Ember.Route.extend({
model(params){
console.log(params.id); //printed a valid id (-KP_nH0EMk3zYqhiWJZ1)
return this.store.findRecord('artist',params.id);
}
});
Run Code Online (Sandbox Code Playgroud)
参考:http://emberjs.com/api/data/classes/DS.Store.html#method_findRecord
归档时间: |
|
查看次数: |
1361 次 |
最近记录: |