简体   繁体   English

流星在集合内部获取自动值_id

[英]Meteor get autovalue _id inside collection

I have this field which is working as I want 我有这个领域正在我想要

tagSlug: {
    type: String,
    label: "slug",
    optional:true,
    autoValue: function() {
      if (this.siblingField('tag').isSet) {
        return URLify2(this.siblingField('tag').value);
      }
    }
  }

But I also want to make another field named nameSlug which needs two fields to be slugged, _id and title if I use this.siblingField('title').value I get title value but nothing hapens if I use this.siblingField('_id').value this may be because _id is not a field inside the form... The final output I want is something like this this-is-awesome-title-xDux1if the last param is _id cutted to 6 or 7 characters I don't know what I will do yet in order to not create large slug strings, but you get the idea. 但是我还想创建另一个名为nameSlug字段,如果使用this.siblingField('title').value ,则需要输入两个字段_idtitle this.siblingField('title').value我得到标题值,但是如果使用this.siblingField('_id').value这可能是因为_id不是表单中的字段...如果最后一个参数被_id this-is-awesome-title-xDux1if 6或7个字符,我想要的最终输出就是这个this-is-awesome-title-xDux1if我不知道我该怎么做才能不创建大段子字符串,但是您明白了。

So basically what I want is to access _id field from inside collection for autoValue another field. 所以基本上我想要从autoValue内部集合中访问_id另一个字段。

I'm using meteor-autoform so I didn't create any Whatever.insert method because they're created automaticaly. 我使用的是meteor-autoform所以我没有创建任何Whatever.insert方法,因为它们是自动创建的。

如果不需要存储它,则可以使用virtualfieldscollection-helpers

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

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