SAPUI5片段视图i18n问题

2020-09-08 16:03发布

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


嗨,

我需要一些帮助,我在获取片段视图以读取i18n文件以在标签上显示文本时遇到问题。

我的项目最初是用SAP Build创建的,在这里我为表启用了排序/过滤/分组功能,这会自动为视图/控制器片段生成代码。

我尝试添加以下行:this.getView()。addDependent(oDialog); 创建从主视图到片段的依赖关系,但这似乎会进一步产生问题...

谁能告诉我在哪里/如何正确创建依赖关系?

这是过滤器视图片段的控制器代码...

 _onFilterButtonPress:函数(oEvent){
 this.mSettingsDialogs = this.mSettingsDialogs ||  {};
 var sSourceId = oEvent.getSource()。getId();
 var oDialog = this.mSettingsDialogs [" FilterDialog"];

 var ConfirmHandler = function(oConfirmEvent){
 var self = this;
 var sFilterString = oConfirmEvent.getParameter('filterString');
 var oBindingData = {};

/*过滤*/
 oBindingData.filters = [];
//将应用于集合的过滤器列表
 var oFilter;
 var vValueLT,vValueGT;
 vValueLT = oDialog.getModel()。getProperty("/img/dateRaised/vValueLT");
 vValueGT = oDialog.getModel()。getProperty("/img/dateRaised/vValueGT");
 如果(vValueLT!=="" || vValueGT!==""){
 oFilter = this.getCustomFilter(" dateRaised",vValueLT,vValueGT);
 oBindingData.filters.push(oFilter);
 sFilterString = sFilterString吗?  sFilterString +',':'过滤依据:';
 sFilterString + = this.getCustomFilterString(true," Date Raised",oFilter.sOperator,vValueLT,vValueGT);
 }
//简单的过滤器(字符串)
 var mSimpleFilters = {},
 sKey;
 for(oConfirmEvent.getParameter(" filterKeys")中的sKey){
 var aSplit = sKey.split(" ___");
 var sPath = aSplit [1];
 var sValue1 = aSplit [2];
 var oFilterInfo = new sap.ui.model.Filter(sPath," EQ",sValue1);
//为每个路径创建一个过滤器映射
 如果(!mSimpleFilters [sPath]){
 mSimpleFilters [sPath] = [oFilterInfo];
 }其他{
 mSimpleFilters [sPath] .push(oFilterInfo);
 }
 }

 for(mSimpleFilters中的var路径){
//同一路径上的所有过滤器都用OR组合
 oBindingData.filters.push(new sap.ui.model.Filter(mSimpleFilters [path],false));
 }
 aCollections.forEach(function(oCollectionItem){
 var oCollection = self.getView()。byId(oCollectionItem.id);
 var oBindingInfo = oCollection.getBindingInfo(oCollectionItem.aggregation);
 var oBindingOptions = this.updateBindingOptions(oCollectionItem.id,oBindingData,sSourceId);
 如果(oBindingInfo.model ===" kpiModel"){
 oCollection.getObjectBinding()。refresh();
 }其他{
 oCollection.bindAggregation(oCollectionItem.aggregation,{
 型号:oBindingInfo.model,
 路径:oBindingInfo.path,
 参数:oBindingInfo.parameters,
 模板:oBindingInfo.template,
 templateShareable:true,
 排序器:oBindingOptions.sorters,
 过滤器:oBindingOptions.filters
 });
 }
//必要时显示过滤字符串
 if(typeof oCollection.getInfoToolbar ===" function"){
 var oToolBar = oCollection.getInfoToolbar();
 如果(oToolBar && oToolBar.getContent()。length === 1){
 oToolBar.setVisible(!! sFilterString);
 oToolBar.getContent()[0] .setText(sFilterString);
 }
 }
 }, 这个);
 } .bind(this);

 函数resetFiltersHandler(){
 oDialog.getModel()。setProperty("/img/dateRaised/vValueLT","");
 oDialog.getModel()。setProperty("/img/dateRaised/vValueGT","");
 }
 函数updateDialogData(filters){
 var mParams = {
 上下文:oReferenceCollection.getBindingContext(),
 成功:function(oData){
 var oJsonModelDialogData = {};
//遍历每个实体
 oData.results.forEach(function(oEntity){
//在地图中添加不同的属性
 for(oEntity中的var oKey){
 如果(!oJsonModelDialogData [oKey]){
 oJsonModelDialogData [oKey] = [oEntity [oKey]];
 }否则,如果(oJsonModelDialogData [oKey] .indexOf(oEntity [oKey])=== -1){
 oJsonModelDialogData [oKey] .push(oEntity [oKey]);
 }
 }
 });
 var oDialogModel = oDialog.getModel();
 oJsonModelDialogData [" dateRaised"] = {
 vValueLT:(oDialogModel && oDialogModel.getProperty("/img/dateRaised"))?  oDialogModel.getProperty("/img/dateRaised/vValueLT"):"",
 vValueGT:(oDialogModel && oDialogModel.getProperty("/img/dateRaised"))?  oDialogModel.getProperty("/img/dateRaised/vValueGT"):""
 };
 如果(!oDialogModel){
 oDialogModel = new sap.ui.model.json.JSONModel();
 oDialog.setModel(oDialogModel);
 }
 oDialogModel.setData(oJsonModelDialogData);
 oDialog.open();
 }
 };
 var sPath;
 var sModelName = oReferenceCollection.getBindingInfo(aCollections [0] .aggregation).model;
//在图表的KPI模式下,getBindingInfo将返回本地JSONModel
 如果(sModelName ===" kpiModel"){
 sPath = oReferenceCollection.getObjectBinding()。getPath();
 }其他{
 sPath = oReferenceCollection.getBindingInfo(aCollections [0] .aggregation).path;
 }
 mParams.filters =过滤器;
 oModel.read(sPath,mParams);
 }
 如果(!oDialog){
 oDialog = sap.ui.xmlfragment({
 fragmentName:" dsn.RiskRegister.view.FilterDialog"
 }, 这个);
 oDialog.attachEvent(" confirm",ConfirmHandler);
 oDialog.attachEvent(" resetFilters",resetFiltersHandler);
 this.mSettingsDialogs [" FilterDialog"] = oDialog;
 }
 var aCollections = [];

 aCollections.push({
 id:" riskTable",
 聚合:"项目"
 });
 var oReferenceCollection = this.getView()。byId(aCollections [0] .id);
 var oSourceBindingContext = oReferenceCollection.getBindingContext();
 var oModel = oSourceBindingContext吗?  oSourceBindingContext.getModel():this.getView()。getModel();
//切换紧凑样式
 jQuery.sap.syncStyleClass(" sapUiSizeCompact",this.getView(),oDialog);
 var designTimeFilters = this.mBindingOptions && this.mBindingOptions [aCollections [0] .id] && this.mBindingOptions [aCollections [0] .id] .filters && this.mBindingOptions [aCollections [0] .id] .filters [undefined];
 updateDialogData(designTimeFilters);
 },
 

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


嗨,

我需要一些帮助,我在获取片段视图以读取i18n文件以在标签上显示文本时遇到问题。

我的项目最初是用SAP Build创建的,在这里我为表启用了排序/过滤/分组功能,这会自动为视图/控制器片段生成代码。

我尝试添加以下行:this.getView()。addDependent(oDialog); 创建从主视图到片段的依赖关系,但这似乎会进一步产生问题...

谁能告诉我在哪里/如何正确创建依赖关系?

这是过滤器视图片段的控制器代码...

 _onFilterButtonPress:函数(oEvent){
 this.mSettingsDialogs = this.mSettingsDialogs ||  {};
 var sSourceId = oEvent.getSource()。getId();
 var oDialog = this.mSettingsDialogs [" FilterDialog"];

 var ConfirmHandler = function(oConfirmEvent){
 var self = this;
 var sFilterString = oConfirmEvent.getParameter('filterString');
 var oBindingData = {};

/*过滤*/
 oBindingData.filters = [];
//将应用于集合的过滤器列表
 var oFilter;
 var vValueLT,vValueGT;
 vValueLT = oDialog.getModel()。getProperty("/img/dateRaised/vValueLT");
 vValueGT = oDialog.getModel()。getProperty("/img/dateRaised/vValueGT");
 如果(vValueLT!=="" || vValueGT!==""){
 oFilter = this.getCustomFilter(" dateRaised",vValueLT,vValueGT);
 oBindingData.filters.push(oFilter);
 sFilterString = sFilterString吗?  sFilterString +',':'过滤依据:';
 sFilterString + = this.getCustomFilterString(true," Date Raised",oFilter.sOperator,vValueLT,vValueGT);
 }
//简单的过滤器(字符串)
 var mSimpleFilters = {},
 sKey;
 for(oConfirmEvent.getParameter(" filterKeys")中的sKey){
 var aSplit = sKey.split(" ___");
 var sPath = aSplit [1];
 var sValue1 = aSplit [2];
 var oFilterInfo = new sap.ui.model.Filter(sPath," EQ",sValue1);
//为每个路径创建一个过滤器映射
 如果(!mSimpleFilters [sPath]){
 mSimpleFilters [sPath] = [oFilterInfo];
 }其他{
 mSimpleFilters [sPath] .push(oFilterInfo);
 }
 }

 for(mSimpleFilters中的var路径){
//同一路径上的所有过滤器都用OR组合
 oBindingData.filters.push(new sap.ui.model.Filter(mSimpleFilters [path],false));
 }
 aCollections.forEach(function(oCollectionItem){
 var oCollection = self.getView()。byId(oCollectionItem.id);
 var oBindingInfo = oCollection.getBindingInfo(oCollectionItem.aggregation);
 var oBindingOptions = this.updateBindingOptions(oCollectionItem.id,oBindingData,sSourceId);
 如果(oBindingInfo.model ===" kpiModel"){
 oCollection.getObjectBinding()。refresh();
 }其他{
 oCollection.bindAggregation(oCollectionItem.aggregation,{
 型号:oBindingInfo.model,
 路径:oBindingInfo.path,
 参数:oBindingInfo.parameters,
 模板:oBindingInfo.template,
 templateShareable:true,
 排序器:oBindingOptions.sorters,
 过滤器:oBindingOptions.filters
 });
 }
//必要时显示过滤字符串
 if(typeof oCollection.getInfoToolbar ===" function"){
 var oToolBar = oCollection.getInfoToolbar();
 如果(oToolBar && oToolBar.getContent()。length === 1){
 oToolBar.setVisible(!! sFilterString);
 oToolBar.getContent()[0] .setText(sFilterString);
 }
 }
 }, 这个);
 } .bind(this);

 函数resetFiltersHandler(){
 oDialog.getModel()。setProperty("/img/dateRaised/vValueLT","");
 oDialog.getModel()。setProperty("/img/dateRaised/vValueGT","");
 }
 函数updateDialogData(filters){
 var mParams = {
 上下文:oReferenceCollection.getBindingContext(),
 成功:function(oData){
 var oJsonModelDialogData = {};
//遍历每个实体
 oData.results.forEach(function(oEntity){
//在地图中添加不同的属性
 for(oEntity中的var oKey){
 如果(!oJsonModelDialogData [oKey]){
 oJsonModelDialogData [oKey] = [oEntity [oKey]];
 }否则,如果(oJsonModelDialogData [oKey] .indexOf(oEntity [oKey])=== -1){
 oJsonModelDialogData [oKey] .push(oEntity [oKey]);
 }
 }
 });
 var oDialogModel = oDialog.getModel();
 oJsonModelDialogData [" dateRaised"] = {
 vValueLT:(oDialogModel && oDialogModel.getProperty("/img/dateRaised"))?  oDialogModel.getProperty("/img/dateRaised/vValueLT"):"",
 vValueGT:(oDialogModel && oDialogModel.getProperty("/img/dateRaised"))?  oDialogModel.getProperty("/img/dateRaised/vValueGT"):""
 };
 如果(!oDialogModel){
 oDialogModel = new sap.ui.model.json.JSONModel();
 oDialog.setModel(oDialogModel);
 }
 oDialogModel.setData(oJsonModelDialogData);
 oDialog.open();
 }
 };
 var sPath;
 var sModelName = oReferenceCollection.getBindingInfo(aCollections [0] .aggregation).model;
//在图表的KPI模式下,getBindingInfo将返回本地JSONModel
 如果(sModelName ===" kpiModel"){
 sPath = oReferenceCollection.getObjectBinding()。getPath();
 }其他{
 sPath = oReferenceCollection.getBindingInfo(aCollections [0] .aggregation).path;
 }
 mParams.filters =过滤器;
 oModel.read(sPath,mParams);
 }
 如果(!oDialog){
 oDialog = sap.ui.xmlfragment({
 fragmentName:" dsn.RiskRegister.view.FilterDialog"
 }, 这个);
 oDialog.attachEvent(" confirm",ConfirmHandler);
 oDialog.attachEvent(" resetFilters",resetFiltersHandler);
 this.mSettingsDialogs [" FilterDialog"] = oDialog;
 }
 var aCollections = [];

 aCollections.push({
 id:" riskTable",
 聚合:"项目"
 });
 var oReferenceCollection = this.getView()。byId(aCollections [0] .id);
 var oSourceBindingContext = oReferenceCollection.getBindingContext();
 var oModel = oSourceBindingContext吗?  oSourceBindingContext.getModel():this.getView()。getModel();
//切换紧凑样式
 jQuery.sap.syncStyleClass(" sapUiSizeCompact",this.getView(),oDialog);
 var designTimeFilters = this.mBindingOptions && this.mBindingOptions [aCollections [0] .id] && this.mBindingOptions [aCollections [0] .id] .filters && this.mBindingOptions [aCollections [0] .id] .filters [undefined];
 updateDialogData(designTimeFilters);
 },
 
付费偷看设置
发送
6条回答
Aaron 3364
1楼 · 2020-09-08 16:22.采纳回答

问题到底是什么?

至少您可以从视图中获取模型,然后将Model设置为片段。

My梦
2楼-- · 2020-09-08 16:21

如果我在这里插入依赖项

 if(!oDialog){
 oDialog = sap.ui.xmlfragment({
 fragmentName:" dsn.RiskRegister.view.FilterDialog"
 }, 这个);
 this.getView()。addDependent(oDialog);
 oDialog.attachEvent(" confirm",ConfirmHandler);
 oDialog.attachEvent(" resetFilters",resetFiltersHandler);
 this.mSettingsDialogs [" FilterDialog"] = oDialog;
 } 

我收到此错误...

huskylover
3楼-- · 2020-09-08 16:29

您的片段状态不佳。

当学会了学习
4楼-- · 2020-09-08 16:17

哈哈! 不开玩笑。

该片段的代码运行良好,直到您尝试引入依赖项为止

小灯塔
5楼-- · 2020-09-08 16:10

信任我,片段就是问题所在。

添加依赖项时,它会尝试使用odata模型加载数据,

Tong__Ming
6楼-- · 2020-09-08 16:28

就像我说的那样,您不必添加依赖项

# p#

true ...我将使用该方法,我想我想使用最佳实践方法,我相信这是增加依赖关系,但是由于清单中已经设置了i18n模型,因此我可以称之为 从那里并将其设置为视图...我已经测试了它的工作原理。

一周热门 更多>