gpt4 book ai didi

javascript - 如何在Init方法中调用函数?

转载 作者:行者123 更新时间:2023-12-03 04:55:37 24 4
gpt4 key购买 nike

我是 sapui5 的新手,我想知道如何在我的 Init 方法中调用函数?

我目前拥有的代码如下:

onInit: function() { 

this.oInitialLoadFinishedDeferred = jQuery.Deferred();
var oEventBus = this.getEventBus();



this.getView().byId("list").attachEventOnce("updateFinished", function() {
this.oInitialLoadFinishedDeferred.resolve();
oEventBus.publish("Master", "InitialLoadFinished", {
oListItem: this.getView().byId("list").getItems()[0]
});
}, this);

oEventBus.subscribe("Detail", "TabChanged", this.onDetailTabChanged, this);

//on phones, we will not have to select anything in the list so we don't need to attach to events
if (Device.system.phone) {
return;
}


this.getRouter().attachRoutePatternMatched(this.onRouteMatched, this);

oEventBus.subscribe("Detail", "Changed", this.onDetailChanged, this);
oEventBus.subscribe("Detail", "NotFound", this.onNotFound, this);
oEventBus.subscribe("Detail", "Cancelled", this.onDetailChangeCancelled, this);

// this.handleSelectDialogPress();

}

有什么建议吗?

最佳答案

我想你已经快可以从 init 调用函数了。

例如,如果您想调用同一 Controller 内的某个函数,则使用'this'关键字(这里'this'指的是当前 Controller ) :

onInit: function() { 
...
this.handleSelectDialogPress();
}

handleSelectDialogPress : function () {
// some code
}

如果你想调用Utils.js中的某个函数,请引用下面的代码

ControllerName.controller.js

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);
}
});
});

MyUtils

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

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

关于javascript - 如何在Init方法中调用函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42443243/

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