Sto provando a seguire this basic Ember.js tutorial ma non ho avuto fortuna con il modello "post". Ho impostato tutto secondo la dimostrazione, ma sto ottenendo l'errore:Uncaught Sono stati inoltrati più oggetti di contesto rispetto ai segmenti dinamici per il percorso: post
Uncaught More context objects were passed than there are dynamic segments for the route: post
Poiché questa è la prima volta che abbia mai lavorato con un app Ember.js, io onestamente non ho idea di cosa questo significa. Qualsiasi aiuto (letteralmente qualsiasi cosa) sarebbe molto apprezzato.
Ecco il mio App.js
App = Ember.Application.create();
App.Store = DS.Store.extend({
adapter: 'DS.FixtureAdapter'
});
App.Router.map(function() {
this.resource('posts', function() {
this.resource('post', { path:'post_id'})
});
this.resource('about');
});
App.PostsRoute = Ember.Route.extend({
model: function() {
return App.Post.find();
}
})
App.Post = DS.Model.extend({
title: DS.attr('string'),
author: DS.attr('string'),
intro: DS.attr('string'),
extended: DS.attr('string'),
publishedAt: DS.attr('date')
});
App.Post.FIXTURES = [{
id: 1,
title: "Rails in Omakase",
author: "d2h",
publishedAt: new Date('12-27-2012'),
intro: "Blah blah blah blah",
extended: "I have no clue what extended means"
}, {
id: 2,
title: "Second post",
author: "second author",
publishedAt: new Date('1-27-2012'),
intro: "second intro",
extended: "Second extended"
}];
E qui è il codice HTML per i posti.
<script type="text/x-handlebars" id="posts">
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<table class='table'>
<thead>
<tr><th>Recent Posts</th></tr>
</thead>
{{#each model}}
<tr><td>
{{#linkTo 'post' this}}{{title}} <small class='muted'>by {{author}}</small>{{/linkTo}}
</td></tr>
{{/each}}
</table>
</div>
<div class="span9">
{{outlet}}
</div>
</div>
</div>
</script>
<script type="text/x-handlebars" id="post">
<h1>{{title}}</h1>
<h2> by {{author}} <small class="muted">{{publishedAt}}</small></h2>
<hr>
<div class="intro">
{{intro}}
</div>
<div class="below-the-fold">
{{extended}}
</div>
</script>
che è stato, grazie tu! – NealR
Mi chiedo perché funzioni come previsto sul video tutorial, potrebbe essere una versione più recente di Ember? –
Giusto per aggiungere a questo, 'risorsa' è stata deprecata in Ember 2.x. Le nuove applicazioni dovrebbero usare 'route' al posto di esso. –