通过淘汰赛向选项添加额外的属性 [英] Add extra attribute to option through Knockout

查看:60
本文介绍了通过淘汰赛向选项添加额外的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要期权的额外价值. 通过选项填充以下选择:groupItems,其中包含"id","description"和"period".

I have the Need for an extra value of an Option. the following select is being populated through the options: groupItems, which contains an 'id', a 'description' and a 'period'.

    <select name="cb_group_1130" id="cb_group_1130" data-bind="options: groupItems(1130), optionsText : 'description',  optionsValue : 'id', optionsPeriod : 'period', value : selectedItem(1130)">
    <option value="0">First</option>
    <option value="1637">second</option>
    <option value="1638">third</option
</select>

在上述情况下,optionsPeriod:'period'不起作用...

in the above case the optionsPeriod: 'period' doesnt work...

我想完成由淘汰赛产生的选项显示的内容:

I want to accomplish that the Knockout generated Option displays this:

<option value="0" period="2" >First</option>

推荐答案

您需要使用optionsAfterRender选项来

You need to use the optionsAfterRender option to post process the rendered option elements:

在您的视图模型中:

this.setPeriod = function (option, item) {
        ko.applyBindingsToNode(option, {
            attr: {
                period: item.period
            }
        }, item);
    }

演示 JSFiddle .

这篇关于通过淘汰赛向选项添加额外的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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