В моем контроллере у меня есть массив с именем bidderArrayText внутри объекта ставки.
Вот мой код контроллера:
import Ember from 'ember';
export default Ember.Controller.extend({
init: function() {
this._super();
var socket = this.get('websockets').socketFor('ws://localhost:9999/');
socket.on('open', this.myOpenHandler, this);
socket.on('message', this.myMessageHandler, this);
socket.on('close', function() {
console.log('closed');
}, this);
},
countdown: {
days: "00",
hours: "00",
minutes: "00",
seconds: "00"
},
bid: Ember.Object.extend({
popUpContainerDisplay: "none",
popUpDisplay: Ember.computed('bid.popUpContainerDisplay', function() {
return Ember.String.htmlSafe("display: " + this.get('bid.popUpContainerDisplay'));
}),
popUpContainerOpacity: 0,
popUpAcceptContainerDisplay: "none",
popUpDeclineContainerDisplay: "none",
popUpWarningContainerDisplay: "none",
popUpWinnerContainerDisplay: "none",
auctionWinnerText: "No winner was found!",
bidderArrayText: []
}),
myOpenHandler: function(event) {
console.log('On open event has been called: ' + event);
},
myMessageHandler: function(event) {
var message = JSON.parse(event.data);
if (message.days != null) {
this.set('countdown.days', ("0" + String(message.days)).slice(-2));
this.set('countdown.hours', ("0" + String(message.hours)).slice(-2));
this.set('countdown.minutes', ("0" + String(message.minutes)).slice(-2));
this.set('countdown.seconds', ("0" + String(message.seconds)).slice(-2));
} else {
this.set('bid.popUpContainerDisplay', message.popUpContainerDisplay);
this.set('bid.popUpContainerOpacity', message.popUpContainerOpacity);
this.set('bid.popUpAcceptContainerDisplay', message.popUpAcceptContainerDisplay);
this.set('bid.popUpDeclineContainerDisplay', message.popUpDeclineContainerDisplay);
this.set('bid.popUpWarningContainerDisplay', message.popUpWarningContainerDisplay);
this.set('bid.popUpWinnerContainerDisplay', message.popUpWinnerContainerDisplay);
this.set('bid.auctionWinnerText', message.auctionWinnerText);
this.set('bid.bidderArrayText', message.bidderArrayText);
}
},
actions: {
sendBid: function() {
var socket = this.get('websockets').socketFor('ws://localhost:9999/');
var bid = this.get('bidTextBox');
var bidder = this.get('bidderTextBox');
var msgToServer = {
bid: bid,
bidder: bidder
};
socket.send(JSON.stringify(msgToServer));
}
}
});
В моем шаблоне я хочу отобразить каждый элемент массива, но не знаю, как это сделать. Вот что у меня есть, но не работает:
{{#each bid.bidderArrayText as |bt index|}}
<p>{{index}}. {{bt}}</p>
{{else}}
<p>Be the first to bid!</p>
{{/each}}
Какой правильный синтаксис? Спасибо.
-1
Jesper
28 Дек 2016 в 04:38
1 ответ
Лучший ответ
Определите класс Bid
и создайте объект в init
import Ember from 'ember';
var Bid = Ember.Object.extend({
init() {
this._super(...arguments);
this.set('bidderArrayText', []);
},
popUpContainerDisplay: "none",
popUpDisplay: Ember.computed('bid.popUpContainerDisplay', function() {
return Ember.String.htmlSafe("display: " + this.get('bid.popUpContainerDisplay'));
}),
popUpContainerOpacity: 0,
popUpAcceptContainerDisplay: "none",
popUpDeclineContainerDisplay: "none",
popUpWarningContainerDisplay: "none",
popUpWinnerContainerDisplay: "none",
auctionWinnerText: "No winner was found!",
//bidderArrayText: [] always do it in init
});
export default Ember.Controller.extend({
init() {
this._super(...arguments);
this.set('bid', Bid.create());
}
});
-1
Ember Freak
28 Дек 2016 в 05:45
Похожие вопросы
Связанные вопросы
Новые вопросы
ember.js
Ember.js - это фреймворк для приложений с компонентами, написанный на JavaScript. Попробуйте облегчить ответ на свой вопрос с помощью предварительно настроенных шаблонов, упомянутых в вики этого тега. (Всегда указывайте версию ember, используемую при описании вашей проблемы)
bid.bidderArrayText
код детали контроллераbid
класс, вы не создали для него объект в контроллере. проверьте этот ответ, это может помочь