Javascript 减速辅助函数的Meteor页面渲染
我想在Meteor JS helper函数中使用jQuery计算表子级的位置,但我总是得到一个空结果,因为helper函数在插入表数据之前返回 这是我的密码:Javascript 减速辅助函数的Meteor页面渲染,javascript,jquery,meteor,Javascript,Jquery,Meteor,我想在Meteor JS helper函数中使用jQuery计算表子级的位置,但我总是得到一个空结果,因为helper函数在插入表数据之前返回 这是我的密码: <table class="table"> <thead> <tr> <th>#</th> <th>Game</th&
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Game</th>
</tr>
</thead>
<tbody>
{{#each games}}
{{> game}}
{{/each}}
</tbody>
</table>
<template name="game">
<tr>
<td>{{counter}}</td>
<td>{{name}}</td>
</tr>
</template>
Template.game.helpers({
counter: function() {
return $('table.table tbody tr td:contains("this.name")').index();
}
});
#
游戏
{{{每场比赛}
{{>游戏}
{{/每个}}
{{counter}}
{{name}}
模板.game.helpers({
计数器:函数(){
return$('table.table tbody tr td:contains(“this.name”)).index();
}
});
应该是这样的:
1试验
2 ABC
3地狱世界
任何帮助都将不胜感激。解决方案的想法是向游戏对象数组中添加名为
索引的附加字段。
稍后在游戏
模板中,您只需使用{{index}
下面的代码应该可以解决您的问题:
var games_with_index = Games.find().map(function(document, index){
document.index = index;
return document;
});
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Game</th>
</tr>
</thead>
<tbody>
{{#each games_with_index}}
{{> game}}
{{/each}}
</tbody>
</table>
<template name="game">
<tr>
<td>{{index}}</td>
<td>{{name}}</td>
</tr>
</template>
var games\u,其中索引=games.find().map(函数(文档,索引){
document.index=索引;
归还文件;
});
#
游戏
{{{#每个游戏{u索引}
{{>游戏}
{{/每个}}
{{index}}
{{name}}
另见:
解决方案的想法是向游戏对象数组中添加名为索引的附加字段。
稍后在游戏
模板中,您只需使用{{index}
下面的代码应该可以解决您的问题:
var games_with_index = Games.find().map(function(document, index){
document.index = index;
return document;
});
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Game</th>
</tr>
</thead>
<tbody>
{{#each games_with_index}}
{{> game}}
{{/each}}
</tbody>
</table>
<template name="game">
<tr>
<td>{{index}}</td>
<td>{{name}}</td>
</tr>
</template>
var games\u,其中索引=games.find().map(函数(文档,索引){
document.index=索引;
归还文件;
});
#
游戏
{{{#每个游戏{u索引}
{{>游戏}
{{/每个}}
{{index}}
{{name}}
另见:
解决方案的想法是向游戏对象数组中添加名为索引的附加字段。
稍后在游戏
模板中,您只需使用{{index}
下面的代码应该可以解决您的问题:
var games_with_index = Games.find().map(function(document, index){
document.index = index;
return document;
});
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Game</th>
</tr>
</thead>
<tbody>
{{#each games_with_index}}
{{> game}}
{{/each}}
</tbody>
</table>
<template name="game">
<tr>
<td>{{index}}</td>
<td>{{name}}</td>
</tr>
</template>
var games\u,其中索引=games.find().map(函数(文档,索引){
document.index=索引;
归还文件;
});
#
游戏
{{{#每个游戏{u索引}
{{>游戏}
{{/每个}}
{{index}}
{{name}}
另见:
解决方案的想法是向游戏对象数组中添加名为索引的附加字段。
稍后在游戏
模板中,您只需使用{{index}
下面的代码应该可以解决您的问题:
var games_with_index = Games.find().map(function(document, index){
document.index = index;
return document;
});
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Game</th>
</tr>
</thead>
<tbody>
{{#each games_with_index}}
{{> game}}
{{/each}}
</tbody>
</table>
<template name="game">
<tr>
<td>{{index}}</td>
<td>{{name}}</td>
</tr>
</template>
var games\u,其中索引=games.find().map(函数(文档,索引){
document.index=索引;
归还文件;
});
#
游戏
{{{#每个游戏{u索引}
{{>游戏}
{{/每个}}
{{index}}
{{name}}
另见:
您是如何呈现该表的?您的选择器似乎无效,请尝试以下操作:return$('table.table tbody tr td:contains(“+this.name+”)).index()代码>谢谢你的帮助!但现在每个条目都有1,应该是降序的。使用index()
可以实现这一点吗?如果看不到其余的代码,很难说。最好是对数据进行操作,而不是像这里这样使用jquery技巧。请告诉我你是如何生成表格的(模板、路线、数据)?我编辑了我的帖子,所以你可以看到我是如何生成表格的。但是,我不知道如何操作数据,因为我还想用jQuery动态添加表数据?您的选择器似乎无效,请尝试以下操作:return$('table.table tbody tr td:contains(“+this.name+”)).index()代码>谢谢你的帮助!但现在每个条目都有1,应该是降序的。使用index()
可以实现这一点吗?如果看不到其余的代码,很难说。最好是对数据进行操作,而不是像这里这样使用jquery技巧。请告诉我你是如何生成表格的(模板、路线、数据)?我编辑了我的帖子,所以你可以看到我是如何生成表格的。但是,我不知道如何操作数据,因为我还想用jQuery动态添加表数据?您的选择器似乎无效,请尝试以下操作:return$('table.table tbody tr td:contains(“+this.name+”)).index()代码>谢谢你的帮助!但现在每个条目都有1,应该是降序的。使用index()
可以实现这一点吗?如果看不到其余的代码,很难说。最好是对数据进行操作,而不是像这里这样使用jquery技巧。请告诉我你是如何生成表格的(模板、路线、数据)?我编辑了我的帖子,所以你可以看到我是如何生成表格的。但是,我不知道如何操作数据,因为我还想用jQuery动态添加表数据?您的选择器似乎无效,请尝试以下操作:return$('table.table tbody tr td:contains(“+this.name+”)).index()代码>谢谢你的帮助!但现在每个条目都有1,应该是降序的。使用index()
可以实现这一点吗?如果看不到其余的代码,很难说。最好是对数据进行操作,而不是像这里这样使用jquery技巧。请告诉我你是如何生成表格的(模板、路线、数据)?我编辑了我的帖子,所以你可以看到我是如何生成表格的。但是,我不知道如何对数据进行操作,因为我还想使用jQuery动态添加表数据。