繁体   English   中英

在Meteor.js中的“自动套用”中为“省略字段”设置值

[英]Setting value for Omitted Field in Autoform in Meteor.js

当使用quickformaldeed:autoform包,我们如何设置,我们已经使用省略字段的值omitFields 忽略该字段是因为我们不希望用户更改其默认值(例如:从Meteor.userId()更改userId)也不会看到该字段。

例:

{{> quickForm collection="Contacts" id="contacts-new-form" type="insert" omitFields="avatarUrl,details.active" buttonContent="Create Contact"}}

如果你想省略字段,但该字段提供默认值,你应该使用autovalue作为记录https://github.com/aldeed/meteor-simple-schema#autovalue

另外,您可以在架构定义中定义自动形成属性,并将其保持在一起,如下所示:

https://github.com/aldeed/meteor-autoform#putting-field-attribute-defaults-in-the-schema

如果这是更新表格,而您不是要查找自动值,而是保留原始值,则可以按照https://github.com/aldeed/meteor-collection2的说明,将该特定字段设为隐藏的输入字段。 #problems,以便它仍然可以通过验证。

但是我会使用可靠的自动值定义。

@Nyxynyx您需要添加此代码。 只需使用钩子并在插入之前添加userId使用。 看下面的例子,希望对您有所帮助。

 var postHooks = { before: { insert: function(doc) { if(Meteor.userId()){ doc.userId = Meteor.userId(); } return doc; } } } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM