Is there any way to get a user object by username or id via javascript?
It is difficult to answer without some more context. You can always do this: (try it in the dev tools for Meta)
Discourse.User.findByUsername("David_Taylor").then(function(user){
console.log("User Found", user);
});
But that will result in an additional request to the server, which may not be necessary.
What are you trying to achieve?
Thanks very much. I am trying to get a list of usersnames with certain custom field attributes. As you correctly pointed out, it will result in many additional calls from the API.
Is it possible to achieve what I intend more gracefully?
If this is just for administrators, you might be able to utilise the data-explorer plugin. If you wanted this to work for all users, you would probably need to create a plugin which adds a new HTTP endpoint.
Sto lavorando a uno dei bug relativi al plugin eventi, dove l’implementazione attuale si basava sui nomi utente. Anche se si tratta di un caso limite, i nomi utente possono cambiare, creando la necessità di poter recuperare un utente tramite il suo id.
Penso che dovrebbe esserci un metodo simile nel core per trovare un utente tramite l’id.
Sono curioso di conoscere il tuo parere a riguardo.
Il tuo plugin dovrebbe essere in grado di aggiornare i riferimenti al nome utente quando questo cambia oppure di aggiungere le rotte e i serializzatori necessari per recuperare i dati.
Controllerò se è possibile farlo nello scenario attuale.
Sì. Dovrò aggiungere un metodo a UsersController per trovare un utente per ID e un metodo nel modello User lato Ember per chiamare questo nuovo metodo del controller.