2012-05-11 2 views
1

나는 공통 JS를 사용하여 스크롤 메뉴를 만들고있다.티타늄 모바일 -보기에 addEventListener

메뉴의 항목은 다른 두 개의 구성 요소 인 아이콘의 이미지보기와이 메뉴의 텍스트 레이블을 포함하는보기입니다.

android 및 ios 시뮬레이터에서 압축이 이상하고 동일하지 않습니다.

안드로이드에서 라벨이나 이미지 뷰에서 클릭이 이루어지면 "잡히지 않은 TypeError : 읽을 수 없습니다 ..." 아이폰에서 아무 것도 실행하지 않습니다.

내가 다른 곳을 (보기 항목에 여전히 있지만) 이미지 또는 labal, 예를 들어 가장자리에 클릭하면, 그것은 완벽하게 작동합니다! 여기

코드이다

함수 menuIcons (itemTab) {

var menuMain = Ti.UI.createView({ 
    layout : 'vertical', 
    backgroundColor : '#333333', 
    height : 125, 
    bottom : 10, 
    left : 10, 
    right : 10, 
    borderRadius : 5.0 
}); 

var menuFirstLine = Ti.UI.createScrollView({ 
    scrollType : 'horizontal', 
    contentHeight : 120, 
    contentWidth : 'auto', 
    layout : 'horizontal', 
    height : 120, 
    marginLeft : 5 
}); 

var items = []; 
var menuIconsItem = require('view/module/menuIconsItem'); 

for(var i in itemTab) { 
    var page = itemTab[i].page; 

    items[i] = new menuIconsItem(itemTab[i]); 

    (function(itemsEvent) { 
     itemsEvent.id = itemTab[i].id; 
     itemsEvent.addEventListener('click', function(e) { 

      Ti.App.fireEvent('main_menu_' + itemsEvent.id, { 
       id : e.source.id 
      }); 
     }) 
    })(items[i]); 

    menuFirstLine.add(items[i]); 
} 
menuMain.add(menuFirstLine); 
return menuMain; 

}

module.exports 용의 menuIcons =;

및 필요한 상품 코드 (VAR menuIconsItem 필요 = ('뷰/모듈/menuIconsItem')) :

함수 menuIconsItem (항목) {

// path for images on Android besoin de centraliser tout ca 
var pathImages = ''; 

var itemImage = Ti.UI.createImageView({ 
    image : item.imageLink, 
    width : 64, 
    height : 64, 
    top : 15 
}); 

var itemLabel = Ti.UI.createLabel({ 
    color : '#afafaf', 
    text : item.text, 
    font : { 
     textAlign : 'center' 
    }, 
    height : 40, 
    top : 80 
}); 

var menuItem = Ti.UI.createView({ 
    width : 120, 
    height : 120, 
    backgroundColor : '#424242', 
    top : 5, 
    left : 5 
}); 

menuItem.add(itemImage); 
menuItem.add(itemLabel); 

return menuItem; 
}

module.exports = menuIconsItem;

답변

2

레이블 및 이미지보기의 ID도 설정해야합니다.

+0

당신은 바위 야,이 지금은 완벽하게 작동합니다! 큰 도움, 정말 고마워! – geoffrey

관련 문제