使用模型进行 ID 分配 [英] Using model for ID assignment

查看:41
本文介绍了使用模型进行 ID 分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用模型绑定为选择控件中的项目分配 ID,但以错误结束.

I tried to assign ID to items in my select control using model binding, but ended with an error.

这是我的代码:

型号:

{
    "languages": [
        {
        "language": "English",
        "locale": "en"
        }, 
        {
        "language": "German",
        "locale": "de"
        }
    ]
}

选择控件:

var oLanguageSelection = new sap.m.Select({
            name:   'languageSelection',
            id:     'languageSelection',
            items: { 
                path: "languages>/languages",
                template: new sap.ui.core.Item({
                    id: "{languages>locale}", //this is the problematic part
                    text: "{languages>language}",
                }),

            },
});

我得到的错误:

Uncaught Error: "{languages>locale}" is not a valid ID.

是否有可能做我想做的事情 - 使用模型绑定分配元素 ID?

Is it possible at all to do what I am trying to do - assign element ID using model binding?

谢谢.

推荐答案

我认为 id 是不可绑定的.ID 指的是也在 DOM 中使用的控件 ID.您尝试做的事情应该通过 key 属性 :)

I think id is not bindable. ID refers to the control id that is also used in the DOM. What you are trying to do should be achieved with the key property :)

var oLanguageSelection = new sap.m.Select({
    name:   'languageSelection',
    id:     'languageSelection',
    selectedKey: "{languages>/languages/0/locale}", // you might want to set a default selection
    items: { 
        path: "languages>/languages",
        template: new sap.ui.core.Item({
            key: "{languages>locale}", // no longer problematic ;)
            text: "{languages>language}"
        })  
    }
});

这篇关于使用模型进行 ID 分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆