使用php创建的选择菜单"选项值"可过滤内部自定义选择错误

时间:2015-03-15 10:28:39

标签: javascript php jquery-mobile

我正在使用JQuery mobile为我的手机构建一个网站。我正在使用" Filterable内部自定义选择"来自1.4.5演示。

当我手动将选项值添加到代码中时,它可以正常工作。

<div class="ui-field-contain">
    <select id="filter-menu" data-native-menu="false" class="filterable-select">
        <option value="SFO">San Francisco</option>
        <option value="LAX">Los Angeles</option>

当我从php文件创建一个时,它可以工作。

<div class="ui-field-contain">
  <select name="Position" id="Position" data-native-menu="false" class="filterable-select"  data-mini="true">
           <option value="<?php echo $PositionID ?>"><?php echo $position ?></option>

然而,当我通过循环来填充多个

foreach($getAllComp as $row)
{
   $PosID = $row["CompanyID"];
   $Pos = $row["Company"];
   $AllPositions .= "<option value=\"".$row['CompanyID']."">".$row['Company']."</option>\n  ";
}

创建

<div class="ui-field-contain">
        <select name="Position" id="Position" data-native-menu="false" class="filterable-select"  data-mini="true">
                   <option value="<?php echo $PositionID ?>"><?php echo $position ?></option>
                <?php echo $AllPositions ?>
        </select>

我收到以下错误, TypeError:listview未定义

指的是

form = listview.jqmData( "filter-form" ) 

from the function supplied from the demo

当查看浏览器检查控制台时,它会显示填充&#34;选项值的PHP&#34;完全像前两次尝试一样。

我已经尝试将这个功能移动到我的页面上的不同位置等等。也许它无法完成? 提前谢谢。

代码是

( function( $ ) {
function pageIsSelectmenuDialog( page ) {
var isDialog = false,
    id = page && page.attr( "id" );
$( ".filterable-select" ).each( function() {
    if ( $( this ).attr( "id" ) + "-dialog" === id ) {
        isDialog = true;
        return false;
    }
});
return isDialog;
}
$.mobile.document.on( "selectmenucreate", ".filterable-select",     function( event ) {
    var input,
        selectmenu = $( event.target ),
        list = $( "#" + selectmenu.attr( "id" ) + "-menu" ),
        form = list.jqmData( "filter-form" );
            if ( !form ) {
        input = $( "<input data-type='search'></input>" );
        form = $( "<form></form>" ).append( input );
        input.textinput();
        list
            .before( form )
            .jqmData( "filter-form", form ) ;
        form.jqmData( "listview", list );
    }

    selectmenu
        .filterable({
            input: input,
            children: "> option[value]"
        })
         .on( "filterablefilter", function() {
            selectmenu.selectmenu( "refresh" );
        });
})
.on( "pagecontainerbeforeshow", function( event, data ) {
    var listview, form;
    if ( !pageIsSelectmenuDialog( data.toPage ) ) {
        return;
    }
    listview = data.toPage.find( "ul" );
    form = listview.jqmData( "filter-form" );
    data.toPage.jqmData( "listview", listview );
    listview.before( form );
})
.on( "pagecontainerhide", function( event, data ) {
    var listview, form;
    if ( !pageIsSelectmenuDialog( data.toPage ) ) {
        return;
    }
    listview = data.prevPage.jqmData( "listview" ),
    form = listview.jqmData( "filter-form" );
    listview.before( form );
});
})( jQuery );

0 个答案:

没有答案