Tom*_*man 9

它还没有在流星版的车把中实现; 关于@index正确渲染的反应性有一个微妙的.你可以在这里阅读更多相关信息:https://github.com/meteor/meteor/issues/489#issuecomment-11270564


Mik*_*cci 9

这对我来说绝对是一种挫败感.与此同时,我制作了一个把手助手来解析任何名为'key'和'value'的对象:

Handlebars.registerHelper('key_value', function(context, options) {
  var result = [];
  _.each(context, function(value, key, list){
    result.push({key:key, value:value});
  })
  return result;
});
Run Code Online (Sandbox Code Playgroud)

这将与#each运营商一起使用,如:

<dl class="attributes">
  {{#each key_value attributes}}
    <dt>{{key}}</dt><dd>{{value}}</dd>
  {{/each}}
</dl>
Run Code Online (Sandbox Code Playgroud)

  • 这非常有效.我使用了一点修改.我只需在`value`中添加一个`_key`字段,然后将`value`直接推送到结果中. (2认同)

小智 6

让它工作的另一种方法是使用带有地图光标功能的标准Meteor模板助手.

这是一个示例,说明如何在将每个索引与集合一起使用时返回索引:

index.html:

<template name="print_collection_indices">
  {{#each items}}
    index: {{ this.index }}
  {{/each}}

index.js:

Items = new Meteor.Collection('items');

Template.print_collection_indices.items = function() {
  var items = Items.find().map(function(doc, index, cursor) {
    var i = _.extend(doc, {index: index});
    return i;
  });
  return items;
};
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

7346 次

最近记录:

11 年,10 月 前