Meteor:将字段的autoValue设置为anther profiles userId

时间:2016-01-29 23:35:48

标签: meteor meteor-collection2 simple-schema

我是Meteor和编程的新手,如果这没有意义,或者您需要更多信息,请告诉我。

我正在加载其他用户的个人资料页面。所以我有2个userIds; this.userId和其他用户ID。我想在执行操作时使用autoValue来保存两个userId。即使我可以在html页面上显示,我也无法弄清楚如何设置其他用户ID。

路径:schema.js

Schemas.class = new SimpleSchema({
    Title: {
        type: String,
        optional: true
    },
    teacherProfile: {
        type: String,
        optional: true,
        autoValue: function() {
            return this.userId
        },
        autoform: {
            type: "hidden"
        }
    },
    studentProfileId: {
        type: String,
        optional: true,
        type: String,
         autoform: {
         defaultValue: "studentProfileId",
         type: "hidden"
    }
    }
});

路径:profile.js

Template.teacherProfile.helpers({
studentProfile: ()=> { 
var id = FlowRouter.getParam('id');

return Meteor.users.findOne({_id: id}); 
}
});

1 个答案:

答案 0 :(得分:0)

这是我的解决方案似乎有效。感谢所有帮助过的人。

路径:schema.js

Schemas.class = new SimpleSchema({
    Title: {
        type: String,
        optional: true
    },
    teacherProfile: {
        type: String,
        optional: true,
        autoValue: function() {
            return this.userId
        },
        autoform: {
            type: "hidden"
        }
    },
    studentProfileId: {
        type: String,
        optional: true,
        autoform: {
            type: "hidden"
        }
    }
});

路径:profile.js

Template.profile.helpers({
    studentProfile: ()=> { 
        var id = FlowRouter.getParam('id');

        return Meteor.users.findOne({_id: id}); 
    },
    studentProfileId: () => {
        return FlowRouter.getParam('id');
    }
)};

路径:profile.html

<template name="profile">

    {{#autoForm collection="Jobs" id="Offer" type="insert"}}

        {{> afQuickField name='Title'}}               
        {{> afQuickField name='studentUserId' value=studentProfileId}}              

        <button type="submit" class="btn btn-primary">Insert</button>

    {{/autoForm}}

</template>