【问题标题】:Meteor: Set autoValue of field to anther profiles usersIdMeteor:将字段的自动值设置为另一个配置文件用户 sId
【发布时间】:2016-05-07 20:49:21
【问题描述】:

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

我正在加载另一个用户的个人资料页面。所以我有 2 个用户 ID; 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}); 
}
});

【问题讨论】:

  • 我认为您不能使用自动值来设置它,因为 SimpleSchema 没有查看 DOM 或模板数据上下文 afaik。您应该在事件处理程序中设置otherUserProfileId,或者更好,只需将隐藏字段值设置为它。
  • 谢谢米歇尔。请告诉我如何设置隐藏字段。
  • 在您的自动表单布局中使用defaultValue 请参阅github.com/aldeed/meteor-autoform#affieldinput
  • 谢谢@michel。当我使用 defaultValue 时,我仍然不确定如何访问其他用户 ID。我尝试从 {{id}} 引用 id,但这不起作用。有什么建议吗?
  • 如何将其他用户带入模板?

标签: meteor meteor-collection2 simple-schema


【解决方案1】:

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

路径: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>

【讨论】:

    猜你喜欢
    • 2010-10-23
    • 2013-01-25
    • 2020-12-16
    • 2017-04-23
    • 2010-11-02
    • 1970-01-01
    • 1970-01-01
    • 2016-08-04
    • 2011-07-17
    相关资源
    最近更新 更多