如何在对象中获取数组对象

时间:2015-05-17 15:47:13

标签: mongodb meteor

以下是我的收藏中的示例文档:

sinceLastMod=sinceLastMod+lastModH+" hours, "

如何从sinceLastMod键获取值以显示在选择框中?

2 个答案:

答案 0 :(得分:0)

Template.name.helpers({
    'selectOptions': function () {
        var obj = MyCollection.findOne({_id: '0001'});
        var options = obj && obj.paymentMethod;
        var helperReadyOptions = [];
        Object.keys(options).forEach(function(key) {
            helperReadyOptions.push({
                label: key,
                value: options[key]
            });
        });
        return helperReadyOptions;
    }
});

<template name="name">
    <select>
        {{#each selectOptions}}
            <option value="{{value}}">{{label}}</option>
        {{/each}}
    </select>
</template>

答案 1 :(得分:-2)

<select>
    {{#each methods}}
        <option value={{value}}>{{method}}</option>
    {{/each}}
</select>

Template.body.helpers({
    methods: function () {
        var ArrMethods = [];
        var objPayment = MyCollection.findOne({_id: '0001'});
        $.each(objPayment.paymentMethod, function (key, value) {
            ArrMethods.push({
                method: key,
                value : value
            });
        });
        return ArrMethods;
    }
});