Modules可以理解成一个个已经编写好的可以拿来就用的功能,比如本节用到的MessageToast
通过layout Editor往页面上拖入一个按钮,改text指定Press所调用的事件,
向导会自动生成controller文件并且增加onClickMe事件
sap.ui.define(["sap/ui/core/mvc/Controller"], function(Controller) {
"use strict";
return Controller.extend("Step6_Modules.controller.App", {
onClickMe: function(oEvent) {
//This code was generated by the layout editor.
}
});
});
这节的目的是引入一个Module MessageToast
,调用Module首先要进行声明,在JS的开头进行引用和声明命名空间。
代码中一共修改了3点
"sap/m/MessageToast"
数组中加入所需的程序执行所需要的Modules(依赖),一旦这两个模块被成功装载,回调函数就会被调用并且我们可以访问这两个对象的参数。"MessageToast"
Function参数中加入参数MessageToast.show()
实际使用模块中的方法
下图是此模块(也可以说是API)的参数说明
执行