ruby-on-rails 轨道7 -刺激控制器连接或/和语法错误

3htmauhk  于 2023-06-07  发布在  Ruby
关注(0)|答案(1)|浏览(195)

我的控制器:

import { Controller } from "@hotwired/stimulus";
import consumer from "channels/consumer";

export default class extends Controller {
  static targets = ["users", "roomId"];

  connect() {
    console.log("");
    this.subscription = consumer.subscriptions.find("RoomChannel");
  }

};

我的房间_频道.js:

import consumer from "channels/consumer"

consumer.subscriptions.create("RoomChannel", {


  connected() {
    // Called when the subscription is ready for use on the server
    console.log("Connected to rooms channel");

  }

},

我的HTML:

<div data-controller="room">
   <!-- get data -->
</div>

console.log()中的结果:

Error connecting controller

TypeError: consumer.subscriptions.find is not a function

我做错了什么?

vwhgwdsa

vwhgwdsa1#

实际上,consumer.subscribes没有'find'方法,但它有几个不同的方法:['create',' add','remove',' reject','forget',' findAll','reload',' notifyAll','notify',' subscribe','confirmSubscription','sendCommand']
您可能希望使用findAll方法,但不要忘记此方法接受完整的通道标识符

this.subscription = consumer.subscriptions.findAll(
      '{"channel":"RoomChannel","room":"Best Room"}')

相关问题