Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在meteor中传递数据和附加模板?_Meteor - Fatal编程技术网

如何在meteor中传递数据和附加模板?

如何在meteor中传递数据和附加模板?,meteor,Meteor,我有一个模板: <div class="container"> {{>sideBar}} {{>gamesContent}} </div> <template name="gamesContent"> <div class="listGames"> <div class="row" id="list_game"> {

我有一个模板:

 <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
            }
        });
    }
}

{{>侧边栏}
{{>游戏内容}
{{{每场比赛}
{{>gameInfo}
{{/每个}}
//在服务器上
流星法({
getListGame:函数(参数){
这是unblock();
var games=HTTP.call(“GET”,urlAPI,{params:params});
返回游戏数据;
}
});
//客户
Template.gamesContent.games=函数(){
返回会话。获取(“游戏”);
}
调用(“getListGame”,{order:“hot”,store:“ios”,limit:'24'},函数(错误,结果){
如果(结果状态){
Session.set('games',result.data.games);
Session.set('cursor',result.data.cursor);
}
});
Template.games.events={
“单击#显示更多”:函数(){
var cursor=Session.get('cursor');
调用(“getListGame”,{order:“hot”,store:“ios”,limit:24,cursor:cursor},函数(错误,结果){
如果(结果状态){
var gameMores=result.data.games;
控制台日志(gameMores);
//我想在这里附加更多的游戏
}
});
}
}
我想单击“显示更多”,它将获取数据并附加“列表”游戏。如何获取模板并传递数据,然后附加列表?请帮帮我?
否则,可以在Meteor中使用scoll Jquery吗?

我给您举了一个很小的例子。我希望我能解决你的问题

//Container for gamesContent, just for a better look behavior
<template name="gamesContentContainer">
  <div class="container">
    //I removed your sidebar
    {{> gamesContent}}
  </div>
</template>


//Your gamesContent template
<template name="gamesContent">
  <div class="listGames">
    <div class="row" id="list_game">
      {{#each games}}
        {{> gameInfo}}
      {{/each}}
    </div>
    <button id="loadmore"></button>
  </div>
</template>

//GameInfo template for every game    
<template name="gameInfo">
  <div>
    {{type}}
  </div>
</template>
直到现在我还不确定这对你是否有效。 如果希望加载更多数据,只需使用新内容设置会话变量

在按钮上设置eventHandler:

Template.gamesContent.events({
  'click #loadmore': function() {
  var data = [{'type' : 'JumpnRun', 'year' : 1990}, {'type' : 'Shooter', 'year' : 2005}, {'type' : 'Simulation', 'year' : 1992}, {'type' : 'JumpnRun', 'year' : 1990}, {'type' : 'Shooter', 'year' : 2005}, {'type' : 'Simulation', 'year' : 1992}];

  Session.set('games', data);     
  }
});

这只是一个小例子。尽管如此,我还是会注意将所有数据保存在会话变量中。也许客户端集合更好。阅读文档中的更多信息。

是的,您可以使用所需的每个jquery插件。你的Meteor.call看起来像是mongo查询。为什么不使用集合来获取数据?你的例子有点模糊。你想让游戏成为你想要迭代的集合的结果集吗?谢谢,我不使用Meteor的minimongo数据库。数据来自API(由MYSQL存储)。在服务器Meteor上,我调用了API,但在客户端,我不知道如何将数据传递到模板,然后附加视图。我在服务器上更新了代码,您可以再次看到。感谢回复并帮助我!重复。回答这里可能重复它的有用和明确,我可以看到。非常感谢你!没问题。如果你喜欢这个答案,你可以投票并接受它,但也许这对你来说仍然不起作用,因为你失去了声誉。周末好。
Template.gamesContent.events({
  'click #loadmore': function() {
  var data = [{'type' : 'JumpnRun', 'year' : 1990}, {'type' : 'Shooter', 'year' : 2005}, {'type' : 'Simulation', 'year' : 1992}, {'type' : 'JumpnRun', 'year' : 1990}, {'type' : 'Shooter', 'year' : 2005}, {'type' : 'Simulation', 'year' : 1992}];

  Session.set('games', data);     
  }
});