简体   繁体   English

如何在 sap ui5 中将组合框默认值设置为会话登录用户 ID

[英]how to set combo box default value as session logged in user id in sap ui5

I am using comboBox control in sap ui5.我在 sap ui5 中使用组合框控件。 I need to show default logged in user id.我需要显示默认的登录用户 ID。 How can I achieve so?我怎样才能做到这一点? This default user id is the part of odata service.此默认用户 ID 是 odata 服务的一部分。 For example I have 10 data(INC0001 to INC0010).例如我有 10 个数据(INC0001 到 INC0010)。 If user INC0004 logged in then by default I want to show that in the comboBox.如果用户 INC0004 登录,那么默认情况下我想在组合框中显示它。 I am getting only first blank right now.我现在只有第一个空白。

XML Code : XML 代码:

<Select id="select1" 
        items="{ path: '/UserSet', sorter: { path: 'zuserid' } }" 
        change="handleChange">

     <core:Item text="{zuserid}" key="{zuserid}"/>
     <layoutData>
         <l:GridData span="XL2 L2"/>
     </layoutData>

</Select>

Session user in sap ui5: sap ui5 中的会话用户:

var userId = sap.ushell.Container.getService("UserInfo").getUser().getId();

Have you tried binding the data in your controller?您是否尝试在控制器中绑定数据?

this.getView().byId("select1").bindItems({
            path: "/UserSet",
            template: new sap.ui.core.Item({
                key: "{zuserid}"
                text: "{zuserid}"
            }),
            events: {
                dataReceived: function () {
                    var userId = sap.ushell.Container.getService("UserInfo").getUser().getId();
                    this.getView().byId("select1").setSelectedKey(userId);
                }.bind(this)
            }
        });

The event dataReceived is triggered once the data is received and at that point it is possible to set the selected key of your ComboBox as @Jorg proposes in the reaction above.一旦接收到数据,就会触发事件dataReceived ,此时可以按照@Jorg 在上面的反应中建议的那样设置ComboBox的选定键。

Select has a parameter called selectedKey you can use for this. Select有一个名为selectedKey的参数,您可以使用它。 Usually this is another model binding but you can do it programmatically as well.通常这是另一种模型绑定,但您也可以通过编程方式进行。

The SDK has an example: https://sapui5.netweaver.ondemand.com/sdk#/entity/sap.m.Select/sample/sap.m.sample.Select/code SDK有一个例子: https : //sapui5.netweaver.ondemand.com/sdk#/entity/sap.m.Select/sample/sap.m.sample.Select/code

            <Select
                forceSelection="false"
                selectedKey="{/SelectedProduct}"
                items="{
                    path: '/ProductCollection',
                    sorter: { path: 'Name' }
                }">
                <core:Item key="{ProductId}" text="{Name}" />
            </Select>

This is the solution for this issue.这是此问题的解决方案。 This will help anyone is looking out for the same.这将有助于任何人都在寻找相同的东西。

 var oData ={
                recipient :{
                   name :"TCS0001"}};

    var oModel =newJSONModel(oData);
    this.getView().setModel(oModel,"NamedModel");


    <ComboBox id="combo1" selectedKey="{NamedModel>/recipient/name}" items="{ path: '/UserSet', sorter: { path: 'zuserid' } }" change="handleChange">
            <core:Item text="{zuserid}" key="{zuserid}"/>
            <layoutData>
             <l:GridData span="XL3 L3"/>
            </layoutData>
           </ComboBox><br>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在控制器(SAP UI5)中设置div的可见性 - how to set visibility of div in controller (SAP UI5) 如何在SAP UI5中的XML模型中设置数组 - How to set array in xml Model in sap ui5 如何在 sap ui5 中的文本字段中设置自动完成或自动建议,如 sap.m.Input? - How to set auto complete or auto suggestion in text field in sap ui5 like sap.m.Input? 如何聚焦 SAP UI5 SmartFilterBar SearchField? - How to focus a SAP UI5 SmartFilterBar SearchField? 如何通过ID设置组合值? - how to set combo value by id? 需要帮助以在SAP UI5的值帮助的新闻事件中找到动态创建的输入控件的ID - Need Help to find id of dynamically created input control in the press event of value help in sap ui5 Fiori 中的会话超时:SAP UI5 或网关层是否提供在用户会话超时时调用的事件 - Session Timeout in Fiori: Does SAP UI5 or the Gateway layer provide an event which gets called when the user's session times out 我可以在 SAP UI5 的标准消息框中提供链接吗? - Can I give a link in standard message box in SAP UI5? 如何在SAP UI5 JS视图中从构造函数对象接收属性值 - How can I receive a value of property from constructor object in sap ui5 js view 如何在JavaScript中设置网格组合框值? - How to set grid combo box value in javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM