I 다음 ember.js 코드가 있습니다인쇄 Ember.js 모델 핸들 바
app.js :
Game = Ember.Application.create({
ready: function() {
Game.gameController.getChallenge();
Game.gameController.participants.pushObject(Game.participants("player1","player1.jpg"));
}
});
Game.challenge = Ember.Object.extend({
challengetype: null,
description: null,
id: null
});
Game.participants = Ember.Object.extend({
name: null,
image: null
});
Game.gameController = Ember.ArrayController.create({
content: [],
current: "",
participants: [],
getChallenge: function() {
var self = this;
var url = "http://api:9393/challenge";
$.getJSON(url, function(data) {
self.insertAt(0,Game.challenge.create(data.challenge));
self.set('current', data.challenge.description);
});
},
});
Game.NewChallengeView = Ember.View.extend({
click: function(evt) {
Game.gameController.getChallenge();
}
});
및 템플릿 :
<div id="participants">
{{#each Game.gameController.participants}}
{{name}}
{{/each}}
</div>
current challenge:
<div class="tooltips-gray">
{{Game.gameController.current}}
</div>
나는이 개 질문을 :
현재 배열의 첫 번째 요소를 사용하는 방법을 모르기 때문에 문자열입니다. 내 생각은 다른 CSS 클래스 배열의 첫 번째 요소를 인쇄하는 것입니다.
둘째, 참여자 배열을 인쇄하는 방법입니다. 참가자 배열에 4 명의 플레이어를 배치하면 각각 4 회 반복됩니다. 하지만 이름이나 이미지와 같은 필드를 인쇄하는 방법을 모르겠습니다.
감사합니다. 내가 여기에 작업 바이올린에 코드를 변환 한
감사합니다. @ luke-melia. 나는 당신의 코드를 점검 할 것이지만 내가 잘못하고있는 주요한 것은 창조에 관한 것이다. 나는 Object.create ({name : "name"}) 대신 Object.create ("name")과 같은 것을하고 있었다. – Seoman