Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery mobile 在jQuery Mobile中构建动态单选按钮列表,但不获取任何单击事件_Jquery Mobile - Fatal编程技术网

Jquery mobile 在jQuery Mobile中构建动态单选按钮列表,但不获取任何单击事件

Jquery mobile 在jQuery Mobile中构建动态单选按钮列表,但不获取任何单击事件,jquery-mobile,Jquery Mobile,我正在使用jqmobile1.0,并根据API返回的json数据动态构建单选按钮列表 我已经能够通过模板化fieldset的内容使它们(大部分)如预期的那样出现,并使用jqMobile从静态标签和单选按钮生成的相同标记: ${showname} ${opendate}&mdash${closedate} 下面是使用模板和更新页面内容的代码: renderSettings显示列表:函数(数据){ $(“#showChooser”) .empty() .append('你参加哪场演出?'); $

我正在使用jqmobile1.0,并根据API返回的json数据动态构建单选按钮列表

我已经能够通过模板化fieldset的内容使它们(大部分)如预期的那样出现,并使用jqMobile从静态标签和单选按钮生成的相同标记:


${showname}
${opendate}&mdash${closedate}

下面是使用模板和更新页面内容的代码:

renderSettings显示列表:函数(数据){
$(“#showChooser”)
.empty()
.append('你参加哪场演出?');
$(“#显示列表”)
.tmpl(数据)
.appendTo(“#showChooser.ui controlgroup controls”);
}
除了丢失圆角之外,列表看起来好像是正常生成的,但剩下的问题是,单击后似乎什么也没有发生。通常情况下,我希望看到选中的单选按钮,标签背景颜色会改变,以获得更多关于选择的视觉反馈

我尝试与标签关联,标签上直接有一个单击处理程序(以及绑定到文档的2个),因此我尝试保存对它的引用,然后重新附加它:

renderSettings显示列表:函数(数据){
//保存对现有单击处理程序的引用,以便我们可以重新应用它
var clk=$(“#显示选择器标签:第一”)。数据(“事件”)。单击[0]。处理程序;
$(“#showChooser”).empty().append('您参加的是哪个节目?');
var newContent=$(“#显示列表”).tmpl(数据).find(“标签”).each(函数)(){
$(此)。单击(clk);
});
newContent.appendTo(“#showChooser.ui控制组控件”);
}
我还尝试在新标记就位后运行
$(“#设置”).page()
(在
渲染显示列表的最后一行,但这似乎没有任何效果

有没有一种被认可的方法来做我正在尝试做的事情,让jQuery Mobile来做它的增强,还是我必须以某种方式将它整合起来?

这就是我提出的那种“黑客”解决方案。它是有效的,但我很想知道是否有更好的方法

renderSettingsShowsList: function ( data ) {
    $("#showChooser")
        .empty()
        .append('<div role="heading" class="ui-controlgroup-label"><h3>Which show are you attending?</h3></div><div class="ui-controlgroup-controls"></div>');

    $("#shows-list").tmpl( data ).appendTo("#showChooser .ui-controlgroup-controls");

    //assign click handler to new form controls to do everything we need it to
    $('#showChooser input:radio').click(function(e) {

        //mark all as not selected
        $("#showChooser input:radio").prop('checked', false);
        $("#showChooser label")
            .attr('data-theme','c')
            .removeClass('ui-btn-up-e')
            .addClass('ui-radio-off')
            .removeClass('ui-radio-on')
            .find(".ui-icon")
                .addClass('ui-icon-radio-off')
                .removeClass('ui-icon-shadow')
                .removeClass('ui-icon-radio-on');

        //style selected option
        var radio = $(this),
            label = radio.next();
        radio.prop('checked', true);
        label.attr('data-theme','e')
            .addClass('ui-btn-up-e')
            .removeClass('ui-radio-off')
            .addClass('ui-radio-on')
            .find(".ui-icon")
                .removeClass('ui-icon-radio-off')
                .addClass('ui-icon-shadow')
                .addClass('ui-icon-radio-on');

    });
}
renderSettings显示列表:函数(数据){
$(“#showChooser”)
.empty()
.append('你参加哪场演出?');
$(“#shows list”).tmpl(data).appendTo(“#showChooser.ui controlgroup controls”);
//将单击处理程序分配给新的表单控件,以执行我们需要它执行的所有操作
$(“#显示选择器输入:收音机”)。单击(函数(e){
//将全部标记为未选中
$(“#显示选择器输入:收音机”).prop('checked',false);
$(“#显示选择器标签”)
.attr('data-theme','c')
.removeClass('ui-btn-up-e')
.addClass('ui-radio-off')
.removeClass('ui-radio-on')
.find(“.ui图标”)
.addClass('ui-icon-radio-off')
.removeClass('ui-icon-shadow')
.removeClass('ui-icon-radio-on');
//样式选择选项
var无线电=$(此),
label=radio.next();
radio.prop(“已检查”,为真);
label.attr('data-theme','e'))
.addClass('ui-btn-up-e')
.removeClass('ui-radio-off')
.addClass('ui-radio-on')
.find(“.ui图标”)
.removeClass('ui-icon-radio-off')
.addClass('ui-icon-shadow')
.addClass('ui-icon-radio-on');
});
}