1

我正在尝试使用 CableReady,我在文档中注意到我可以使用相关的 JavaScript 事件。

但是,没有关于如何使用它们的示例。

例子:

cable_ready["MyChannel"].morph(
  selector:                 "string",   # required - string containing a CSS selector or XPath expression
  html:                     "string",   # [null]   - the HTML to assign
  children_only:            true|false, # [null]   - indicates if only child nodes should be morphed... skipping the parent element
  permanent_attribute_name: "string",   # [null]   - an attribute name that prevents elements from being updated i.e. "data-permanent"
  focus_selector:           "string",   # [null]   - string containing a CSS selector
)

文档有:

JavaScript Events

cable-ready:before-morph

cable-ready:after-morph

但是我不知道如何在我的 Javascript 中调用这些事件。

以前有人用过这些吗?

4

1 回答 1

0

您可以使用这样的after-morph事件:

document.addEventListener("cable-ready:after-morph", () => {  
  console.log('after-morph') 
})

现在,假设我们刚刚outer_html从我们的 Rails 控制器执行了一个操作,并且我们想要捕获 after 事件:

document.addEventListener("cable-ready:after-outer-html", (event) => {
  console.log('after-outer-html') 
})
于 2021-04-02T16:41:54.660 回答