1
當運行我的項目,我得到:類型錯誤Controller.extend不是一個函數
Error: failed to load 'stock/controller/plant.controller.js' from ./controller/plant.controller.js: TypeError: Controller.extend is not a function
請讓我知道如何解決它。
plant.controller.js
sap.ui.define([
"sap/ui/core/mvc/Controller",
"jquery.sap.global",
"stock/Formatter",
"sap/ui/core/routing/History",
"sap/ui/model/json/JSONModel"
], function (jQuery, Formatter, Controller, History, JSONModel) {
"use strict";
var TableController = Controller.extend("stock.controller.plant", {
onInit: function() {
var oModel = new JSONModel(jQuery.sap.getModulePath("sap.ui.demo.mock", "/products.json"));
this.getView().setModel(oModel);
},
getRouter : function() {
return sap.ui.core.UIComponent.getRouterFor(this);
},
onNavBack: function (oEvent) {
var oHistory = History.getInstance();
var sPreviousHash = oHistory.getPreviousHash();
if (sPreviousHash !== undefined) {
window.history.go(-1);
} else {
this.getRouter().navTo("input", {}, true /*no history*/);
}
}
});
return TableController;
});
Component.js
sap.ui.define([
"sap/ui/core/UIComponent",
"sap/ui/core/mvc/XMLView",
"sap/ui/model/json/JSONModel"
], function(UIComponent, JSONModel, XMLView) {
"use strict";
var Component = UIComponent.extend("stock.Component", {
metadata: {
manifest: "json",
getTable: function() {
return this._rootView.getContent()[0];
}
},
publicMethods: [
"getTable"
],
dependencies: {
libs: [
"sap.m",
"sap.ui.layout"
]
},
rootView: "stock.view.input",
config: {
sample: {
files: [
"view.input.view.xml",
"controller.main.controller.js",
"Formatter.js"
],
description : "In this example assisted input is provided with table-like suggestions where several columns can display more details."
}
},
init : function() {
UIComponent.prototype.init.apply(this, arguments);
this.getRouter().initialize();
}
});
Component.prototype.createContent = function() {
this._rootView = sap.ui.xmlview({ viewName : "stock.view.plant" });
return this._rootView;
};
return Component;
});
現在我只能查看第二視圖(plant.view.xml)...但我想從我的第一個觀點(input.view.xml)第二視圖來瀏覽其最初是否正在發生。請給我建議如何顯示第一個視圖(input.view.xml),然後從那裏導航。我在之前的文章中添加了component.js。請讓我知道是否需要其他代碼片段提供一些幫助。 – Ajay
考慮到您在問題中顯示的內容,您似乎使用了一種奇怪的應用程序/組件配置。你應該在ui5文檔中查看它。 –