[英]Newline in Ember handlebars helper?
對於在特定情況下如何使用此幫助器,我仍然有些模糊。 我從一個對象數組中拉出一個隨機對象,並在單擊按鈕時顯示它們。 每個對象都有3個道具:單詞,語言,反式。 渲染對象時,我真的希望它顯示如下
字
朗格
翻譯
我將它渲染時居中,但全部集中在一行中。 這是我的助手的代碼:
Ember.Handlebars.helper('randomize', function(myArray, options) {
var random = myArray[Math.floor(Math.random() * myArray.length)];
return random.word + random.language + random.trans;
});
所以我愚蠢的問題是,渲染時如何添加換行符?
我認為一個更好的工作工具將是組件。 組件自動帶有一個模板,用於完全執行您想做的事情,然后您的顯示邏輯與業務邏輯分離。
App.RandomWordComponent = Ember.Component.extend({
word: null,
language: null,
translation: null,
createRandomWord: function() {
this.set('word', Math.random());
this.set('language', Math.random());
this.set('translation', Math.random());
}.on('didInsertElement')
});
和模板:
<p style="font-weight: bold">
Word: {{word}}
</p>
<p>
language: {{language}}
</p>
<p>
translation: {{translation}}
</p>
然后在其他模板中使用它:
{{random-word}}
我對其進行了簡化,因此您需要根據需要進行調整,但是希望這可以為您指明正確的方向。 完整的例子在這里
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.