回答のグリッドを生成する外部サーバーからのJSON応答があります。彼らが行くルートはEmberに設定されていますが、結果を追加する際にヘルパーにリンクを使用する方法を理解できず、クリックするとアプリケーションがリロードされます。Emberの投稿応答からlink-toを追加します。
export default Ember.Component.extend({
actions: {
switchGenre(genre){
$.post('https://somewhere.com/search',{'genre':genre},function (data) {
$('#stations').empty()
var activeRow = 0;
$('#stations').append('<div class="row" id="row'+activeRow+'">')
$.each(data,function(index,station){
if(index%4==0 && index > 0){
activeRow++;
$('#stations').append('<div class="row" id="row'+activeRow+'">')
}
$('#row'+activeRow).append('<a href="/station/'+station.id+'"></a>')
})
})
}
}
});
jqueryで直接DOMを操作するのではなく、レスポンスを使って '{{each} 'ブロックを書くのはなぜですか? – kumkanillam
しかし、JSファイルでHandlebarsを使用するにはどうしたらいいですか? '{{各データを|ステーションのインデックスとして|}}' –