سؤال

لدي رمز Ember.js التالي:

app.js: giveacodicetagpre.

و template: giveacodicetagpre.

لدي 2 أسئلة:

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

  • الثاني هو، كيف طباعة صفيف المشاركين.إذا وضعت 4 لاعبين على صفيف المشاركين، فإن كل منها يجعل 4 تكرارات.لكنني لا أعرف كيفية طباعة الحقول مثل الاسم أو الصورة.

    شكرا.

هل كانت مفيدة؟

المحلول

I've converted your code to a working fiddle here: http://jsfiddle.net/KbN47/8/

The most natural way to bind to the first element of the array is using firstObject. As of Ember 0.9.5, firstObject and lastObject are not observable, due to performance impact. The Ember team hopes to fix this in the future.

If you don't plan to make many changes to the array in your app, the naive override of firstObject I provided in the fiddle should work for you.

Regarding your second question, I extracted the participants to separate controller for clarity and fixed a few issues with your code.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top