Sto provando a caricare un modello utente di dati ember da un percorso piuttosto che accettare un nome utente o un ID.Utilizzo di una lumaca invece di un ID
Ho modificato il metodo di ricerca RESTAdapter per passare l'ID dalla risposta JSON a didFindRecord
, ma non viene passato nulla alla mia visualizzazione. Sembra che Ember stia ancora provando a usare il nome utente come id del modello.
Il mio router si presenta così:
App.Router = Em.Router.extend({
location: 'history'
, root: Em.Route.extend({
user: Em.Route.extend({
route: '/users/:slug'
, connectOutlets: function(router, context) {
router.get('applicationController').connectOutlet('user', context)
}
, serialize: function(router, context) {
return { slug: context.get('username') || context.get('id') }
}
, deserialize: function(router, params) {
return App.User.find(params.slug)
}
})
})
})
E il mio metodo find è simile al seguente:
var CustomAdapter = DS.RESTAdapter.extend({
find: function(store, type, id) {
var root = this.rootForType(type)
this.ajax(this.buildURL(root, id), 'GET', {
success: function(json) {
this.didFindRecord(store, type, json, json[root].id)
}
})
}
})
App.store = DS.Store.create({
revision: 6
, adapter: CustomAdapter.create({ namespace: 'api' })
})
è che la richiesta Ajax in realtà licenziato ? (Si fa a ottenere i dati?) Potrebbe essere un problema con i cambiamenti di propagazione –
provare a fare questo: Ember.run (questo, function() { this.didFindRecord (negozio, tipo, JSON, JSON [root] .id); }); –