我的模板:如何传递数据并在流星中追加模板?
<div class="container">
{{>sideBar}}
{{>gamesContent}}
</div>
<template name="gamesContent">
<div class="listGames">
<div class="row" id="list_game">
{{#each games}}
{{>gameInfo}}
{{/each}}
<!--/games-->
</div>
</div>
</template>
// On server
Meteor.methods({
getListGame: function (params) {
this.unblock();
var games = HTTP.call("GET",urlAPI,{params:params});
return games.data;
}
});
// On client
Template.gamesContent.games = function() {
return Session.get('games');
}
Meteor.call("getListGame", {order: "hot", store:"ios", limit:'24' }, function (error, result) {
if(result.status) {
Session.set('games', result.data.games);
Session.set('cursor', result.data.cursor);
}
});
Template.games.events = {
'click #show_mores': function(){
var cursor = Session.get('cursor');
Meteor.call("getListGame", {order: "hot", store:"ios", limit:24, cursor:cursor }, function (error, result) {
if(result.status) {
var gameMores = result.data.games;
console.log(gameMores);
// i want to append more games here
}
});
}
}
我想点击#show_more,它将得到的数据和追加#list_game。如何获取模板并传递数据,然后添加list_game?请帮帮我? 否则,可以在流星中使用scoll jquery?
是的,你可以使用你想要的每个jquery插件。你的Meteor.call看起来像一个mongo查询。为什么不使用集合来获取数据?你的例子有点模糊。你想让游戏成为你想要迭代的集合的结果集吗? – chaosbohne
谢谢,我不使用流星数据库minimongo。数据来自API(由MYSQL存储)。在服务器流星我已经调用的API,但在客户端上我不怎么传递数据到模板,然后附加视图 –
我已经更新代码在服务器上,你可以再次看到。谢谢回复并帮助我! –