احصل على كائن مستخدم بواسطة اسم المستخدم أو المعرف في JavaScript

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.

أعمل على إصلاح أحد الأخطاء المتعلقة بإضافة الفعاليات، حيث كان التطبيق الحالي يعتمد على أسماء المستخدمين. وعلى الرغم من أن هذا يمثل حالة هامشية، إلا أن أسماء المستخدمين قد تتغير، مما يستدعي القدرة على جلب المستخدم من خلال معرفه (id).

أعتقد أنه يجب أن توجد طريقة مماثلة في النواة للعثور على المستخدم عبر المعرف.

أهتم بمعرفة آرائكم في هذا الشأن.

يجب أن يكون بإمكان الإضافة إما تحديث إشارات اسم المستخدم عند تغيير اسم المستخدم، أو إضافة المسارات والمُعرِّفات الضرورية التي تحتاجها لاسترجاع البيانات.

سأتحقق مما إذا كان من الممكن القيام بذلك في السيناريو الحالي.

نعم. سأحتاج إلى إضافة طريقة إلى UsersController للعثور على مستخدم حسب المعرف (id)، وإضافة طريقة في نموذج User على جانب Ember لاستدعاء هذه الطريقة الجديدة في المتحكم.