2013-02-04 96 views
1

我试着通过阅读Todo-List示例中如何处理标签以及如何在缔约方示例中处理RSVPS来解决这个问题,但我无法弄清楚实现我的目标的一般方法。 我有一个计划收集具有名称OWNERID和excerciselist通过索引访问数组

Plans.insert({名称:名称[I]中,OWNERID:1,excerciselist:excercises});

现在在这个Excerciselist中,我想通过ID添加一个未定义的ExactcAmout。 我有一个Excercisecollection具有以下:

Excercises.insert({名称:名称[I],肌肉:肌肉[I]中,设备:设备[I]中,描述:说明[I]});

现在所有这些练习在缺省情况下都有一个唯一的_id元素。 将事情添加到excerciselist否问题我可以通过Push来完成。 但我不明白的是,我如何通过它的索引访问excerciselist中的某些ID。

我只能通过访问整个字符串数组和输出在HTML

{{#each planarray}} {{excerciselist}} {{/每}} 但是没有方法可行做smoething像 {{excerciselist}}

我也曾尝试只excerciselist返回planarray,但问题是,因为它是唯一索引,而不是映射它不能由LiveHTML访问。

有没有人有一个想法如何解决这个问题?

回答

0

为什么不在Excersies插入中添加唯一标识的字段?

Excercises.insert({ uniqueID: [i], name: names[i], muscle: muscles[i], device: devices[i], description: descriptions[i]}); 

这样你就可以根据uniqueID字段得到你想要的锻炼。

哦,你应该可能称之为“唯一ID”的东西更有意义。

+0

像我已经说过,每一个条目已经作为uniqueid in _id – MMB

0

我发现了一点小小的解决方法,这不正是我想到的,但它完成了工作。

Template.editplan.excercises = function() { 
    var names = []; 
    var add = []; 
    var adder = null; 
    for(var i = 0; i < this.excerciselist.length; i++) 
    { 
     add[i] = []; 
     adder = Excercises.find({_id: this.excerciselist[i]}); 
     add[i]['_id'] = this.excerciselist[i]; 
     add[i]['location'] = i; 
     adder.forEach(function (obj) { 
     add[i]['name'] = obj.name; 
     }); 
     names.push(add[i]); 
    } 
    return names; 
    }; 

基本上我做了一个新的磁盘阵列中,我把数据我想有这样我就可以在LiveHTML读它看到下面

{{#each planarray}} 
     <h1>{{name}}</h1> 
     {{#each excercises}} 
     {{name}} 
     {{/each}} 
     <select name="selectedexcercise{{_id}}" id="selectedexcercise{{_id}}"> 
      {{> excerciseoption}} 
     </select> 
     <input type="button" class="addtoplan" value="Eine Übung hinzfügen"> 
    {{/each}} 

例子,但必须有一个更有效的还是不错的方式....至少我希望如此!