在 controller.js 中找不到名称“jQuery"错误 [英] Cannot find name 'jQuery' error in controller.js
问题描述
我正在 VS Code 中开发 UI5 应用程序.我在 *.controller.js
文件中添加了一个新的计数函数,为了显示来自服务器的计数,我在下面的代码中使用了 jQuery:
jQuery.each(this._mFilters, function (sFilterKey, oFilter) {oModel.read("/portfolios/$count", {过滤器:o过滤器,成功:功能(oData){var sPath = "/";+ sFilterKey;oViewModel.setProperty(sPath, oData);}});});
不幸的是,我收到以下错误:
有谁知道为什么会触发错误以及如何修复它?
非常感谢任何帮助或建议.
我假设 this._mFilters
是一个对象.在这种情况下,请尝试:
Object.keys(this._mFilters).map(sFilterKey => {const oFilter = this._mFilters[sFilterKey];oModel.read("/portfolios/$count", {过滤器:[oFilter],成功:函数(sCount){const sPath = `/${sFilterKey}`;oViewModel.setProperty(sPath, +sCount);},});});
还有参数 filters
等待一个数组而不是单个 Filter 实例.>
如果仍然首选 jQuery,请包含 sap/ui/thirdparty/jquery"
(以前是 jquery.sap.global"
) 到控制器的依赖列表.
sap.ui.define([sap/ui/core/mvc/Controller",//...,sap/ui/第三方/jquery",], 函数(控制器,/*...,*/jQuery) {//jQuery 在这里可用});
I am developing a UI5 app in VS Code.
I added a new count function to the *.controller.js
file, and in order to display the count from the server, I am using jQuery like in the following code:
jQuery.each(this._mFilters, function (sFilterKey, oFilter) {
oModel.read("/portfolios/$count", {
filters: oFilter,
success: function (oData) {
var sPath = "/" + sFilterKey;
oViewModel.setProperty(sPath, oData);
}
});
});
Unfortunately, I get the following error:
Does anyone know why was the error triggered and how it can be fixed?
Any help or suggestion is much appreciated.
I assume this._mFilters
is an object. In that case, try with:
Object.keys(this._mFilters).map(sFilterKey => {
const oFilter = this._mFilters[sFilterKey];
oModel.read("/portfolios/$count", {
filters: [ oFilter ],
success: function(sCount) {
const sPath = `/${sFilterKey}`;
oViewModel.setProperty(sPath, +sCount);
},
});
});
Also the parameter filters
awaits an array instead of a single Filter instance.
If jQuery is still preferred, include "sap/ui/thirdparty/jquery"
(formerly "jquery.sap.global"
) to the dependency list of the controller.
sap.ui.define([
"sap/ui/core/mvc/Controller",
// ...,
"sap/ui/thirdparty/jquery",
], function(Controller,/*...,*/ jQuery) {
// jQuery is here available
});
这篇关于在 controller.js 中找不到名称“jQuery"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!