简体   繁体   English

jQuery Mobile自定义翻转框获取选定值

[英]JQuery Mobile Custom Flipbox get selected value

I have the following customflipbox created using the Datebox jQM plugin: 我使用Datebox jQM插件创建了以下customflipbox:

<div data-role="fieldcontain">
    <label for="cf" data-i18n="config.localelabel"></label>
    <input name="cf" type="date" data-role="datebox" id="cf" data-options='{"mode":        "customflip",
"customData": [  {
"input": true,
"name": "",
"data": ["Italiano","English","Espanol","Deutsch","Francais","русский"]
}],
"useNewStyle": false,
"overrideStyleClass": "ui-icon-dice",
"useButton":false,
"useFocus" : true
}' />

When I pick a value I need to populate the cf input field with the selected value, I tried: 当我选择一个值时,我需要使用所选值填充cf输入字段,我尝试过:

$('cf').on('datebox',function(p,e){
    if (p.method === 'set') {
        e.stopImmediatePropagation();
        $(this).val(selectdata[p.value]);
    }
});

on the 'datebox' event, but it seems the most i can get is that the field is populated with the index of the selected value but I need the actual string (eg English). 在'datebox'事件上,但似乎我能获得的最多是该字段填充有所选值的索引,但我需要实际的字符串(例如英语)。

Any insight? 有见识吗?

Thank you. 谢谢。 M. M.

Add the data array in code and then you can reference it in 'set' event: 在代码中添加数据数组,然后可以在'set'事件中引用它:

<div data-role="fieldcontain">
    <label for="cf" data-i18n="config.localelabel"></label>
    <input name="cf" type="date" data-role="datebox" id="cf" data-options='{"mode":        "customflip",
"useNewStyle": false,
"overrideStyleClass": "ui-icon-dice",
"useButton":false,
"useFocus" : true
}' />

In code create a global variable called selectdata that is the array of values: 在代码中,创建一个名为selectdata的全局变量,该变量是值数组:

var selectdata = ["Italiano","English","Espanol","Deutsch","Francais","русский"];
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
    'customData': [{
        'input': true,
            'name': '',
            'data': selectdata
    }],
        "useHeader": false,
        "overrideCustomSet": "OK"
});

$('#cf').on('datebox', function (e, p) {
    if (p.method === 'set') {
        e.stopImmediatePropagation();
        $(this).val(selectdata[p.value]);
    }
});

DEMO DEMO

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM