-1
在我的控制器中,我在競價對象中有一個名爲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}}
什麼是正確的語法?謝謝。
創建對象您的代碼看起來很完美。包括'bid.bidderArrayText'控制器部件代碼 – kumkanillam
@kumkanillam完成。 – Jesper
它看起來'bid'是類,你還沒有在控制器中爲此創建對象。檢查此[答案](http://stackoverflow.com/a/41310280/5771666)這可能會有所幫助 – kumkanillam