未触发来自 XML 片段的事件处理程序 [英] Event handlers from XML fragment not triggered
问题描述
我想将 liveChange
事件附加到基于可重用 Fragment
的 Dialog
字段的 Input
字段>(演练步骤 19:重用对话框).
在 XML 模板 HelloDialog.fragment.xml
中,我添加了:
<输入id =输入-b"类型=密码";liveChange = ".onLiveChange";placeholder = "输入您的密码";/>
在片段的控制器 HelloDialog.js
中,我添加了:
onLiveChange: function (oEvent) {const sNewValue = oEvent.getParameter("value");this.byId("getValue").setText(sNewValue);控制台日志(sNewValue");}
然后我在 DevTools 中在这个方法中设置了一个断点,并尝试在相关的 Input
中输入一个文本,并期望断点会被触发但没有任何反应.
我已经尝试将 onLiveChange
添加到我调用此片段的视图的控制器中,也添加到 Component.js
中,但仍然没有反应.>
问题是为什么在我的情况下没有触发 onLiveChange
?在 SAP 示例:输入 - 值更新 一切正常,但他们使用的是常规视图,而不是基于片段的对话框.
为了能够处理来自片段的事件,控制器实例或应该传递给controller
创建片段时:
{//My.controller.jsonLiveChange:函数(){//...},打开:函数(){//...片段加载({id: oView.getId(),name: "demo.my.view.fragment.SomeFragment",controller: this,//或包含事件处理程序的普通对象}).然后(/*...*/);},}
var oFragmentController = {//...onLiveChange: function() {//...},};片段加载({id: oView.getId(),name: "sap.ui.demo.walkthrough.view.HelloDialog",controller: oFragmentController,//或者 `this` 如果处理程序是在 HelloDialog 中定义的.}).then(/*...*/);
同样适用于现在-已弃用 sap.ui.*fragment
:
sap.ui.xmlfragment(oView.getId(), "myFragmentName", this);//自 1.58 起弃用.
I'd like to attach a liveChange
event to the Input
field of the reusable Fragment
-based Dialog
(Walkthrough Step 19: Reuse Dialogs).
In XML-template HelloDialog.fragment.xml
I've added:
<Input
id = "input-b"
type = "Password"
liveChange = ".onLiveChange"
placeholder = "Enter your password" />
In the fragment's controller HelloDialog.js
I've added:
onLiveChange: function (oEvent) {
const sNewValue = oEvent.getParameter("value");
this.byId("getValue").setText(sNewValue);
console.log("sNewValue");
}
Then I set in DevTools a break point in this method and try to type a text in the relevant Input
and expect that the break point will be fired but nothing happens.
I've tried to add onLiveChange
into the view's controller from where I call this fragment and to the Component.js
as well, but still no reaction.
The question is why onLiveChange
is not triggered in my case? In SAP Sample: Input - Value Update everything is OK, but they use a regular view, not a fragment-based dialog.
In order to enable handling events from a fragment, a controller instance or a plain object should be passed to controller
when creating the fragment:
{ // My.controller.js
onLiveChange: function() {
// ...
},
open: function() {
// ...
Fragment.load({
id: oView.getId(),
name: "demo.my.view.fragment.SomeFragment",
controller: this, // or a plain object that contains event handlers
}).then(/*...*/);
},
}
In the case of the Walkthrough Step 19: Reuse Dialogs:
var oFragmentController = {
// ...
onLiveChange: function() {
// ...
},
};
Fragment.load({
id: oView.getId(),
name: "sap.ui.demo.walkthrough.view.HelloDialog",
controller: oFragmentController, // or `this` if the handlers are defined in the HelloDialog.
}).then(/*...*/);
The same goes for the now-deprecated sap.ui.*fragment
:
sap.ui.xmlfragment(oView.getId(), "myFragmentName", this); // deprecated since 1.58.
这篇关于未触发来自 XML 片段的事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!