문제

The following code does not work when the url is /company/martin:

 this.route('scheduledTasks', {
    path: '/company/:name',
    data: {
      items:
      function(){
        return scheduledTasks.find({company: this.params.name});
      }
    }

While this does work:

 this.route('scheduledTasks', {
    path: '/company/:name',
    data: {
      items:
      function(){
        return scheduledTasks.find({company: "martin"});
      }
  }

I tried several solutions, but it seems that this.params.name does not exist or cannot be accessed??

도움이 되었습니까?

해결책

this.params.name needs to be evaluated within the context of the route, and I believe that only can happen if data is a function and not an object literal. Try this:

this.route('scheduledTasks', {
  path: '/company/:name',
  data: function() {
    var company = this.params.name;
    return {
      items: function() {
        return scheduledTasks.find({company: company});
      }
    };
  }
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top