gpt4 book ai didi

sapui5 - 如何在SAPUI5 Controller 中调用实用函数

转载 作者:行者123 更新时间:2023-12-02 11:39:31 26 4
gpt4 key购买 nike

我想创建一个自定义实用程序文件(JavaScript 文件),即 /webapp/util/MyUtil.js

假设这是MyUtil的内容:

function myFunc(input) {
// some code
}

并且存在一个 View 和 Controller ,即 View1.xmlView1.js。如何从 View1.js 调用 myFunct(input)

最佳答案

推荐的方法是创建一个模块(类似于类),它可以在将来处理您的依赖项:

sap.ui.define([], function() {
"use strict";

return {
myFunc: function(input) {
// some code
}
};
});

稍后,在您的 Controller 中将此文件包含在依赖项列表中并通过此对象访问它:

sap.ui.define([
"sap/ui/core/mvc/Controller",
"./MyUtils"
], function(Controller, MyUtils) {
"use strict";

return Controller.extend("your.controller.ControllerName", {
myFunc2: function(input) {
MyUtils.myFunc(input);
}
});
});

确保指定正确的路径。如果它是 Controller 的文件夹,您可以使用示例,否则指向正确的文件夹。

关于sapui5 - 如何在SAPUI5 Controller 中调用实用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37376838/

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