我正在尝试制作一个XMLHttpRequest从外部文件加载 HTML 并将文件内容插入到div.
当我运行该函数时,它会在所有不够充分的正文中插入 HTML。
我的代码:
--------------------------> HTML <--------------------- -----
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="shit.js" charset="utf-8"></script>
<link rel="stylesheet" href="index.css">
<title>Test</title>
</head>
<body>
<button type="button" name="button" onclick="send()">Click me</button>
<div class="view" id="view"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
--------------------------> CSS <--------------------- -----
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="shit.js" charset="utf-8"></script>
<link rel="stylesheet" href="index.css">
<title>Test</title>
</head>
<body>
<button type="button" name="button" onclick="send()">Click me</button>
<div class="view" id="view"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
--------------------------> JS <--------------------- -----
.view {
margin-top: 5vh;
height: 15vh;
width: 80vw; …Run Code Online (Sandbox Code Playgroud) 我想将一个liveChange事件附加到Input基于可重用的字段Fragment(Dialog演练步骤 19:重用对话框)。
在 XML 模板中HelloDialog.fragment.xml我添加了:
<Input
id = "input-b"
type = "Password"
liveChange = ".onLiveChange"
placeholder = "Enter your password" />
Run Code Online (Sandbox Code Playgroud)
在片段的控制器中HelloDialog.js我添加了:
onLiveChange: function (oEvent) {
const sNewValue = oEvent.getParameter("value");
this.byId("getValue").setText(sNewValue);
console.log("sNewValue");
}
Run Code Online (Sandbox Code Playgroud)
然后我在 DevTools 中在此方法中设置一个断点,并尝试在相关内容中键入文本Input,并期望断点将被触发,但什么也没有发生。
我尝试onLiveChange从我调用此片段的位置添加到视图的控制器中Component.js,但仍然没有反应。
为什么onLiveChange我的情况没有触发?在 SAP示例中:输入 - 值更新一切正常,但它们使用常规视图,而不是基于片段的对话框。
要i18n在 UI5 中配置功能,我在 manifest.json 中使用以下代码段sap.ui5:
"models": {
"i18n": {
"preload": true,
"settings": {
"bundleName": "webapp.i18n.i18n",
"bundleUrl": "i18n/i18n.properties",
"fallbackLocale": "en",
"supportedLocales": [
"en"
]
},
"type": "sap.ui.model.resource.ResourceModel"
}
},
Run Code Online (Sandbox Code Playgroud)
感谢supportedLocales并且fallbackLocale我不希望 UI5 会请求不存在的本地化,但实际上我仍然观察到不需要的 404 请求i18n_en_US.properties:
GET http://localhost:3000/i18n/i18n_en_US.properties 404 (Not Found)
Run Code Online (Sandbox Code Playgroud)
我认为supportedLocales和背后的整个想法fallbackLocale是减少本地化请求的数量,这些请求不存在且未在supportedLocales.
我的问题:
为什么 UI5 无论如何尝试请求,i18n_en_US.properties尽管en_US没有出现在supportedLocales?
是否可以摆脱对不受支持的语言环境的额外请求?
在官方 UI5 文档中,有一个如何加载 a 的代码片段sap.ui.core.Fragment:
sap.ui.require(["sap/ui/core/Fragment"], async function(Fragment){
this.myFragment = await Fragment.load({
name: "my.useful.VerySimpleUiPart"
});
});
Run Code Online (Sandbox Code Playgroud)
同时,我可以sap.ui.core.Fragment使用 a loadFragmentof加载sap.ui.core.mvc.Controller:
this.myFragment = await this.loadFragment({
name: "my.useful.VerySimpleUiPart"
});
Run Code Online (Sandbox Code Playgroud)
thisBaseController是一个基于的实例sap.ui.core.mvc.Controller。
据我了解,在幕后loadFragment使用:sap.ui.core.Fragment.load
通过 加载片段
sap.ui.core.Fragment.load。
如果是这样,我们为什么需要Controller.loadFragment?SAP 有官方建议使用哪种方法吗?