gpt4 book ai didi

javascript - 加载模块不起作用时设置繁忙状态

转载 作者:行者123 更新时间:2023-11-28 10:38:45 25 4
gpt4 key购买 nike

我想在单击sap.m.Button时加载第三方模块。由于库需要一点时间来加载,我想显示繁忙的 View 。但它不起作用。我想加载第三方模块,加载并执行该模块的功能后,我想将 View busy 设置为 false

Controller :

onPressDownload: function () {
var view = this.getView();
view.setBusy(true);
jQuery.sap.require('pdfmake.build.pdfmake');
jQuery.sap.require('pdfmake.build.vfs_fonts');
if (pdfMake) {
var docDef = "";
pdfMake.createPdf(docDef).download();
view.setBusy(false);
}
},

查看:

var oBtn = new sap.m.Button({
press: [oController.onPressDownload, oController]
});

jQuery.sap.require 进行同步调用时,view.setBusy 应该可以工作。但它没有按预期工作,并且 view.setBusy() 立即重置为 false。我是不是做错了什么?

最佳答案

问题

所有控件(包括 View )都提供 busyIndi​​catorDelay,默认值为 1000 毫秒。 IE。如果延迟短于 1 秒,应用程序将不会显示忙碌指示符。 Fiori 设计指南建议延迟一秒。 src 您可以将其减少到 0 毫秒。但是,这并不能解决实际问题,因为..:

实际问题

As jQuery.sap.require makes a synchronous call, view.setBusy should work.

不幸的是,情况恰恰相反。 因为它进行同步调用,处理繁忙状态无法按预期工作,因为同步请求完全卡住了浏览器的主线程/事件循环。即:

control.setBusy(true);
// <synchronous calls>;
control.setBusy(false);

相同

control.setBusy(true);
control.setBusy(false);

停止使用已弃用的 jQuery.sap.require 函数,并将其替换为 sap.ui.require 或将依赖项添加到顶部的 sap.ui.define

onPressDownload: function() {
this.getView().setBusy(true);
sap.ui.require([ // Instead of jQuery.sap.require("...")
"pdfmake/build/pdfmake",
"pdfmake/build/vfs_fonts",
], function(/*...*/) {
// ...
this.getView().setBusy(false);
}.bind(this));
},

参见https://stackoverflow.com/a/45277948/5846045

API sap.ui.require 可用于按需异步获取模块/JS 文件。

<小时/>

⚠️请确保在引导时启用index.html中的模块异步加载:

// since 1.58.2
data-sap-ui-libs="sap.ui.core, sap.m, ..."
data-sap-ui-async="true" // replaces preload="async" and xx-async="true"
// for 1.58.1 and below
data-sap-ui-libs="sap.ui.core, sap.m, ..."
data-sap-ui-preload="async"
data-sap-ui-xx-async="true"

如果缺少这些设置,JS 文件仍然会同步加载!

关于javascript - 加载模块不起作用时设置繁忙状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55822950/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com