0

我不知道如何使用这个漂亮的 slug 包输出正确的数据,任何帮助将不胜感激。

我正在使用 Meteor 大气中的以下软件包。https://atmospherejs.com/todda00/friendly-slugs

我有一个表单提交,它将提交发送到一个集合,并将页面路由到“works/titleOfPost”

我正在使用友好的 slug decleration 连接到我的收藏。这是那个代码。

Works = new Mongo.Collection('works');
Works.friendlySlugs(
  {
    slugFrom: 'jobTitle',
    slugField: 'slug',
    debug : true
  }
);

这是我的表单提交发送给我的地方,这似乎适用于正确的 url。

 Router.go('works', {slug: event.jobTitle});  

这就是我认为问题所在,在我的路由器中。

Router.map( function () {


    this.route("/works/:slug", {
      name: 'works',
      waitOn: function() {
        return this.subscribe('works', this.params.slug);
      },
      data: function() {
        return Works.findOne({
          slug: this.params.slug
        });
      }
    });
  }

这是控制台中的调试。

friendlySlugs DEBUG: = Begin runSlug
todda00_friendly-slugs.js:314 friendlySlugs DEBUG: Options↓
todda00_friendly-slugs.js:315 Object
todda00_friendly-slugs.js:317 friendlySlugs DEBUG: Modifier= false
todda00_friendly-slugs.js:317 friendlySlugs DEBUG: Create= false
todda00_friendly-slugs.js:317 friendlySlugs DEBUG: Slugging From= lkfjsalkfjdakl
todda00_friendly-slugs.js:317 friendlySlugs DEBUG: SlugBase before reduction= lkfjsalkfjdakl
todda00_friendly-slugs.js:317 friendlySlugs DEBUG: SlugBase after reduction= lkfjsalkfjdakl
todda00_friendly-slugs.js:317 friendlySlugs DEBUG: Highest indexed base found= undefined
todda00_friendly-slugs.js:317 friendlySlugs DEBUG: finalSlug= lkfjsalkfjdakl
todda00_friendly-slugs.js:317 friendlySlugs DEBUG: = Set to update
todda00_friendly-slugs.js:314 friendlySlugs DEBUG: Final Doc↓
todda00_friendly-slugs.js:315 Objectauthor: "bob"clientName: "dflkasl;fkjasfklj"companyName: "ksldfjalkjfdkl;"friendlySlugs: ObjectheroImg: "/cfs/files/ImagesHero/x55bsAaYrAB6aJriC/Screen Shot 2015-09-11 at 11.13.02 AM.png?token=eyJhdXRoVG9rZW4iOiJsX0JueUFMQXFhOHJTSlIzZE9KU1MzM2x4dm92ZmprQ2lEY1JqWUlhNU1pIn0%3D"jobText: "<p>dfasfsafas</p>"jobTitle: "lkfjsalkfjdakl"logoImg: "/cfs/files/Images/eqjmnZtdzg6zEMm3v/acorn.gif?token=eyJhdXRoVG9rZW4iOiJsX0JueUFMQXFhOHJTSlIzZE9KU1MzM2x4dm92ZmprQ2lEY1JqWUlhNU1pIn0%3D"slug: "lkfjsalkfjdakl"submitted: Mon Sep 14 2015 15:15:36 GMT-0700 (PDT)userId: "es6YC98DdFvbrZGbW"__proto__: Object

这是我的收集数据

{
  "_id": "TZnxLmmxcupEuW6o6",
  "clientName": "dflkasl;fkjasfklj",
  "companyName": "ksldfjalkjfdkl;",
  "logoImg": "/cfs/files/Images/eqjmnZtdzg6zEMm3v/acorn.gif?token=eyJhdXRoVG9rZW4iOiJsX0JueUFMQXFhOHJTSlIzZE9KU1MzM2x4dm92ZmprQ2lEY1JqWUlhNU1pIn0%3D",
  "jobTitle": "lkfjsalkfjdakl",
  "jobText": "<p>dfasfsafas</p>",
  "heroImg": "/cfs/files/ImagesHero/x55bsAaYrAB6aJriC/Screen Shot 2015-09-11 at 11.13.02 AM.png?token=eyJhdXRoVG9rZW4iOiJsX0JueUFMQXFhOHJTSlIzZE9KU1MzM2x4dm92ZmprQ2lEY1JqWUlhNU1pIn0%3D",
  "userId": "es6YC98DdFvbrZGbW",
  "author": "bob",
  "submitted": "2015-09-14T22:15:36.655Z",
  "friendlySlugs": {
    "slug": {
      "base": "lkfjsalkfjdakl",
      "index": 0
    }
  },
  "slug": "lkfjsalkfjdakl"
}
4

1 回答 1

0

而不是在 Router.go 调用中使用 jobTitle,您应该使用 slug,如下所示:

Router.go('works', {slug: event.slug});

另外,我看不到您的发布方法,因此请确保您接受 slug 参数并使用{slug:slug}而不是标题本身查找文档。

于 2015-11-03T16:31:17.790 回答