我可以动态设置ID和视图名称吗?

时间:2022-06-13 05:23:31
    <core:mvc.XMLView id="{path:' AssignmentModel>/AssignmentType' ,formatter:'.getViewName'}" 
            viewName="{path:' AssignmentModel>/AssignmentType' ,formatter:'.getViewName'}" 
            height="100%" visible="true"/>

I want view to be loaded based on assignemnt type. I tried to dynamically load the view from controller, based on type. but that itsnt working as expected.

我想根据assignemnt类型加载视图。我试图根据类型从控制器动态加载视图。但它的工作正如预期的那样。

1 个解决方案

#1


0  

If you use a View in an XMLView it will be created once. Even if your binding was working it would be OneTime, meaning it is only resolved once, which is obviously not what you are looking for.

如果在XMLView中使用View,它将被创建一次。即使你的绑定工作也是OneTime,这意味着它只能解决一次,这显然不是你想要的。

You either have to use Routing as qualiture already mentioned or load your content dynamically from your controller and manually insert it in your view hierarchy. You could still use a PropertyBinding to observe property changes like this:

您必须使用路由作为已提及的资质,或者从控制器动态加载内容并手动将其插入视图层次结构中。您仍然可以使用PropertyBinding来观察属性更改,如下所示:

 var binding = new sap.ui.model.PropertyBinding("AssignmentModel", "/AssignmentType");
 binding.attachChange(function() {
   var sViewName = this.getViewName(this.getModel("AssignmentModel").getProperty("/AssignmentType");
   var oView = sap.ui.xmlview({
     id: sViewName
     viewName: sViewName
   });
   // pack your view whereever you want, clean the old view before
   this.getView().addContent(oView);
 }, this)

You might need to use sap.ui.model.odata.ODataPropertyBinding depending on the model you are using.

您可能需要使用sap.ui.model.odata.ODataPropertyBinding,具体取决于您使用的型号。

Code above is untested but it 'should' work.

上面的代码未经测试但它“应该”有效。

GL Chris

#1


0  

If you use a View in an XMLView it will be created once. Even if your binding was working it would be OneTime, meaning it is only resolved once, which is obviously not what you are looking for.

如果在XMLView中使用View,它将被创建一次。即使你的绑定工作也是OneTime,这意味着它只能解决一次,这显然不是你想要的。

You either have to use Routing as qualiture already mentioned or load your content dynamically from your controller and manually insert it in your view hierarchy. You could still use a PropertyBinding to observe property changes like this:

您必须使用路由作为已提及的资质,或者从控制器动态加载内容并手动将其插入视图层次结构中。您仍然可以使用PropertyBinding来观察属性更改,如下所示:

 var binding = new sap.ui.model.PropertyBinding("AssignmentModel", "/AssignmentType");
 binding.attachChange(function() {
   var sViewName = this.getViewName(this.getModel("AssignmentModel").getProperty("/AssignmentType");
   var oView = sap.ui.xmlview({
     id: sViewName
     viewName: sViewName
   });
   // pack your view whereever you want, clean the old view before
   this.getView().addContent(oView);
 }, this)

You might need to use sap.ui.model.odata.ODataPropertyBinding depending on the model you are using.

您可能需要使用sap.ui.model.odata.ODataPropertyBinding,具体取决于您使用的型号。

Code above is untested but it 'should' work.

上面的代码未经测试但它“应该”有效。

GL Chris