简体   繁体   中英

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.

So basically what I want is to access _id field from inside collection for autoValue another field.

I'm using meteor-autoform so I didn't create any Whatever.insert method because they're created automaticaly.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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