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
Mongodb 如何使用{{#each}}显示Meteor中的许多嵌套对象?_Mongodb_Meteor_Spacebars - Fatal编程技术网

Mongodb 如何使用{{#each}}显示Meteor中的许多嵌套对象?

Mongodb 如何使用{{#each}}显示Meteor中的许多嵌套对象?,mongodb,meteor,spacebars,Mongodb,Meteor,Spacebars,使用下面的MongoDB子文档如何使用{{{{each}}块帮助器(或者任何方法)来迭代循环中的对象 "recurring": { "T12345" : { "amount" : 102, "created_at" : "2014-09-29T17:43:18.414627+00:00", "status": "pending", "guid" : "T12345" }, "T12346" : {

使用下面的MongoDB子文档如何使用
{{{{each}}
块帮助器(或者任何方法)来迭代
循环中的对象

"recurring": {
    "T12345" : {
        "amount" : 102,
        "created_at" : "2014-09-29T17:43:18.414627+00:00",
        "status": "pending",
        "guid" : "T12345"
    },
    "T12346" : {
        "amount" : 102,
        "created_at" : "2014-09-30T17:45:02.768939+00:00",
        "status": "succeeded",
        "guid" : "T12346",

    }
}
JS文件

Template.subscription.helpers({
subscription: function () {
    return this.recurring.transactions; //The subscription filters out the records marked viewable: false
},
    fname: function() {
        return this.customer.fname;
    },
    lname: function() {
        return this.customer.lname;
    },
    amount: function() {
        return this.debit.amount / 100;
    },
    trans_guid: function(key) {
        return this.recurring.transactions.key; //not sure how I can get the guid since the object that holds this property is named using the same guid
    }
});
Template.subscription.helpers({
    values: function() {
        return this;
    },
    status: function() {
        return this.value.status;
    },
    fund: function(parentContext) {
        return parentContext.debit.donateTo;//getDonateTo();
    },
    trans_date: function() {
        return moment(this.value.updated_at).format("MM-DD-YYYY hh:mma");
    },
    amount: function() {
        return "$" + (Math.floor(this.value.amount) / 100).toFixed(2);
    },
    trans_guid: function() {
        return this.value.guid;
    }
});
Template.registerHelper('addKeys', function (all) {
    return _.map(all, function(i, k) {
        return {key: k, value: i};
    });
});
HTML文件

<table class="table bootstrap-datatable datatable small-font">
<thead>
    <tr>
        <th>Status</th>
        <th>Date</th>
        <th>Fund</th>
        <th>Amount</th>
        <th>Number</th>
    </tr>
</thead>   
<tbody>
    {{#each subscription}}
        <tr>
            <td><span class="label label-success">{{status}}</span></td>
            <td>{{trans_date}}</td>
            <td>{{fund}}</td>
            <td>{{amount}}</td>
            <td><b>{{trans_guid}}</b></td>
        </tr>                       
    {{/each}}                                                                               
</tbody>
</table>
JS:

Template.registerHelper('addkey',函数(全部){
返回映射(全部,函数(i,k){
返回{key:k,value:i};
});
});
HTML:


{{#每个addkey订阅}
{{#带值}}
{{status}}
{{trans_date}}
{{基金}
{{amount}}
{{trans_guid}}
{{/与}}
{{/每个}}

我更新了问题以显示更多代码。您能帮助我了解如何在问题更新中使用您的答案吗?您的html和数据库记录不匹配,因此我不确定您想从哪里获取数据,例如,
fund
,但我认为我刚才对我的答案所做的更新正是您想要的。我添加了Mongodb文档的要点。我知道我不太明白这里到底发生了什么,或者我想我能想出如何在我的特殊情况下使用你的答案。我只是在网上找不到任何澄清的东西。我在我的代码中使用了你的更改,但我仍然无法让它工作。谢谢你更新你的答案。有了这个文档,你知道我需要在JS文件中做什么才能得到正确的数据吗?我还是不明白你的问题。如果您能说出您希望使用mongodb文档的哪些字段,以及您希望看到该文档的输出,可能会有所帮助。这就是事务中的所有内容:{}我正在描绘一个表,每个事务有一行。行中的数据将是amount、created_at和其他一些数据。
Template.subscription.helpers({
    values: function() {
        return this;
    },
    status: function() {
        return this.value.status;
    },
    fund: function(parentContext) {
        return parentContext.debit.donateTo;//getDonateTo();
    },
    trans_date: function() {
        return moment(this.value.updated_at).format("MM-DD-YYYY hh:mma");
    },
    amount: function() {
        return "$" + (Math.floor(this.value.amount) / 100).toFixed(2);
    },
    trans_guid: function() {
        return this.value.guid;
    }
});
Template.registerHelper('addKeys', function (all) {
    return _.map(all, function(i, k) {
        return {key: k, value: i};
    });
});