Ember,要重定向的组件

niknxzdl  于 2022-11-23  发布在  其他
关注(0)|答案(1)|浏览(142)

在我的ember应用程序中,我有一个activities路线,带有相应的路线,控制器和一些组件,模板包含:
{{carousel-activities activities=model}}
carousel-activities包含:

{{#each activities as |activity|}}
    <li>{{carousel-block activity=activity}}</li>
  {{/each}}

carousel-block包含一些HBS来显示每个活动的内容:

<div class="carousel-block">
  {{#link-to 'activity' activity class="small"}}
    <div class="full-width-image">
      <img src="{{activity.image}}" class="img img-responsive full-width" alt="{{activity.title}}">
    </div>
    <div class="text-center">
      <h1>{{activity.title}}</h1>
    </div>
  {{/link-to}}
</div>

阻止组件使用ember-gestures监视panDown,当事件发生时,阻止组件将浏览器重定向到活动详细信息页面。
第一个
如果我加载活动路线,并在其上向下滑动(引发panDown事件),我会在控制台中得到以下错误:

panDown
ember.debug.js:6208 DEPRECATION: Ember.View#transitionTo has been deprecated, it is for internal use only [deprecation id: ember-views.view-transition-to]
        at HANDLERS.(anonymous function) (http://localhost:4200/assets/vendor.js:16380:7)
        at raiseOnDeprecation (http://localhost:4200/assets/vendor.js:16290:12)
        at HANDLERS.(anonymous function) (http://localhost:4200/assets/vendor.js:16380:7)
        at invoke (http://localhost:4200/assets/vendor.js:16396:7)
        at deprecate (http://localhost:4200/assets/vendor.js:16349:32)
        at Object.deprecate (http://localhost:4200/assets/vendor.js:26468:37)
        at _emberMetalMixin.Mixin.create.transitionTo (http://localhost:4200/assets/vendor.js:52805:24)
        at panDown (http://localhost:4200/assets/myproject.js:261:12)
        at _emberRuntimeSystemObject.default.extend.trigger (http://localhost:4200/assets/vendor.js:55654:23)
ember.debug.js:42747 Uncaught TypeError: Cannot read property 'enter' of undefined_emberMetalMixin.Mixin.create._transitionTo @ ember.debug.js:42747_emberMetalMixin.Mixin.create.transitionTo @ ember.debug.js:42736panDown @ carousel-activities.js:24_emberRuntimeSystemObject.default.extend.trigger @ ember.debug.js:45584superWrapper @ ember.debug.js:23209Backburner.run @ ember.debug.js:678Backburner.join @ ember.debug.js:702run.join @ ember.debug.js:21280_emberMetalAssign.default.handleEvent @ ember.debug.js:46458exports.default._emberMetalMixin.Mixin.create._Mixin$create.handleEvent @ ember.debug.js:43395exports.default._emberRuntimeSystemObject.default.extend._bubbleEvent @ ember.debug.js:44482(anonymous function) @ ember.debug.js:44424jQuery.event.dispatch @ jquery.js:4737elemData.handle @ jquery.js:4549triggerDomEvent @ hammer.js:2497Manager.emit @ hammer.js:2438emit @ hammer.js:1474Recognizer.emit @ hammer.js:1485inherit.emit @ hammer.js:1764Recognizer.tryEmit @ hammer.js:1502Recognizer.recognize @ hammer.js:1549Manager.recognize @ hammer.js:2314inputHandler @ hammer.js:517MEhandler @ hammer.js:826Input.domHandler @ hammer.js:430
nc1teljy

nc1teljy1#

您不能从组件调用transitionTo()。最好的方法是发送一个动作,它将从控制器执行转换。

export default Component.extend(RecognizerMixin, {
  recognizers: 'pan',
  panDown() {
    console.log("panDown");
    this.attrs.showDetailsAction(this.get('activity'));
  }
});

然后在你的控制器中定义动作:

export default Ember.Controller.extend({
  actions: {
    showDetails(activityData) {
      this.transitionToRoute('activity', activityData);
    }
  }
});

并将动作传递给您的元件:

{{carousel-block activity=activity showDetailsAction=(action 'showDetails')}}

相关问题