2012-04-23 4 views
3

jQuery Mobile에서 사용자 정의 선택 메뉴를 사용 중입니다. 사용자 정의 팝업 메뉴에 아이콘을 넣어 각각 option을 표시하고 싶습니다. 내가 지금처럼 각 optiondata-icon 속성을 적용하고 있습니다 :사용자 정의 jQuery Mobile 아이콘 선택

<select name='mySelect' id='mySelect' data-icon='gear'> 
    <option value='0' data-icon='star'>Option 0</option> 
    <option value='1' data-icon='star'>Option 1</option> 
    <option value='2' data-icon='star' selected="selected">Option 2</option> 
</select> 

FWIW을, 난 이미 내 사용자 정의 아이콘 선택 버튼 자체가 작동하는지 확인했습니다. 커스텀 메뉴에 아이콘이 나타날 것으로 예상하는데 나는 완전히 잘못 되었습니까?

답변

4

이 없습니다 여기에 기본적으로 지원되지만 그것을 가능하게하는 코드의 빠른 조각 : 여기

//wait for the correct page to initialize 
$(document).delegate('#home', 'pageinit', function() { 

    //loop through each of the SELECT elements in this page 
    $.each($(this).find('select'), function() { 

     //get the ID of this select because it's menu's ID is based off of it 
     var currentID = this.id; 

     //iterate through each of the OPTION elements for this SELECT element 
     $.each($(this).find('option'), function (index, element) { 

      //if the OPTION element has the `data-icon` attribute 
      if ($(element).attr('data-icon') != undefined) { 

       //update the menu for this SELECT by adding an icon SPAN element 
       //to each of the OPTION elements that has a `data-icon` attribute 
       $('#' + currentID + '-menu').children().eq(index).find('.ui-btn-inner').append('<span class="ui-icon ui-icon-' + $(element).attr('data-icon') + ' ui-icon-shadow" />'); 
      } 
     }); 
    }); 
});​​ 

는 데모입니다 : http://jsfiddle.net/NHQGD/

+0

이 나는 ​​두려워 무엇의 종류 .. 기능 요청 양식은 어디에 있습니까? =) – FMM

+0

꽤 작은 플러그인 인'336 bytes minified'입니다. – Jasper

+0

예, 작지만 모든 자료를 포함하지는 않습니다 : 예를 들어'data-iconpos'. 또한'selectmenu()'를 호출하거나 동적 내용에 대해'create'를 트리거하는 것을 처리하지 않습니다. 그 대답에서 기대하는 것은 아니지만, 당신은 나의 표류를 얻습니다, 나는 확실합니다.) – FMM

관련 문제