Hi there, i have a news system and i can pull all data but when i click the image i can't get the details:( i have tried for "e.row.data" and "e.source.data" but can't get the details from the opening window? i am working for ios. Thanks
var baseWin = Ti.UI.currentWindow; baseWin.navBarHidden = true; var win = Ti.UI.createWindow({ title:'News', barColor: barcolor_ui, navBarHidden:false }); var close = Ti.UI.createButton({ title:'close' }); close.addEventListener("click",function(e){ baseWin.close(); }); win.setRightNavButton(close); Ti.UI.currentWindow.orientationModes = [ Titanium.UI.LANDSCAPE_LEFT,Ti.UI.LANDSCAPE_RIGHT ]; var navGroup; var isAndroid = false; var navGroup = Ti.UI.iPhone.createNavigationGroup( { window : win }); win.navGroup = navGroup; if (Ti.Platform.name == 'android') { isAndroid = true; } var rows = 0; var columns = 0; var thumbPadding = 2; var rowPosition = 2; var rowPositionReset = 2; var padding = 5; var columnPosition = 15; var json_data = []; var imagesArray = []; var xhr_request = Titanium.Network.createHTTPClient( ); xhr_request.setTimeout(5000000); xhr_request.onerror = function(e){ alert('Check your internet Connection'); } var url = 'http://www.xxx.com/news.php'; Ti.API.info(url); xhr_request.open("GET",url); xhr_request.onload = function(){ Ti.API.info('Response: '+ xhr_request.responseText); try{ json_data = JSON.parse(this.responseText); displayImages( ); }catch(e){ alert('check your internet connection 2'); } } xhr_request.send(); function displayImages( ){ for(var i=0;i<json_data.sorgu.length;i++){ imagesArray.push({resim:json_data.sorgu[i].imagefile, caption: json_data.sorgu[i].title+'\r\n'+ json_data.sorgu[i].message }); } var scrollView = Ti.UI.createScrollView({ maxZoomScale:4.0, contentWidth : 'auto', contentHeight : 'auto', top : -5, backgroundColor : 'transparent', showVerticalScrollIndicator : true, showHorizontalScrollIndicator : false }); for (i = 0, b = imagesArray.length; i < b; i++) { if (columns % 2 == 0 && rows != 0) { columnPosition += 280 + thumbPadding; rowPosition = rowPositionReset; } var img = Ti.UI.createImageView({ defaultImage:default_image_ui, image : big_image +"thumb2_"+imagesArray[i].resim, width : 270, height: 270, left : 0, top : 0, zIndex:10 }); var baslik = Ti.UI.createLabel({ color:'#FFF', text:imagesArray[i].caption, font:{ fontSize:12, fontWeight:'bold', fontFamily:'Trebuchet MS' }, top:0, left:280, width:220, height:260 }); var container = Ti.UI.createView({ width:500, height:270, backgroundColor:'#000', myID : i, left : rowPosition, top : columnPosition, }); container.add(img); container.add(baslik); img.borderColor = '#000'; img.borderWidth = 4; img.backgroundPaddingLeft = 0; img.backgroundPaddingRight = 0; img.backgroundPaddingTop = 0; img.backgroundPaddingBottom = 0; img.backgroundLeftCap = 0; img.backgroundTopCap = 0; img.backgroundColor = '#000'; img.addEventListener('click', function(e) { var win_photo = Ti.UI.createWindow({ backgroundColor:arkaplan_sade_ui, title:'News Detail', windowInfo : imagesArray, width:600, navBarHidden:false, barColor:barcolor_ui, }); var baslik = Ti.UI.createLabel({ text:e.source.caption, left:0, top:320 }); win_photo.add(baslik); navGroup.open(win_photo,{animated:true}); }); scrollView.add(container); columns++; rows++; rowPosition += 510 + padding; } win.add(scrollView); baseWin.add(navGroup); baseWin.open() }
1 Answer
Accepted Answer
you need to pass the response to the function
....
....
....
json_data = JSON.parse(this.responseText);
displayImages( json_data);
....
....
....
function displayImages(json_data){
for(var i=0;i<json_data.sorgu.length;i++){
....
....
....also you dont see the details cause you are not putting them on the image object. you are not given much info about the json object but it looks like the data you want to show its store in the label. Try adding thisvar img = Ti.UI.createImageView({ defaultImage:default_image_ui, image : big_image +"thumb2_"+imagesArray[i].resim, width : 270, height: 270, left : 0, top : 0, zIndex:10, data: imagesArray[i].caption//<<<<<< }); .... .... .... img.addEventListener('click', function(e) { var win_photo = Ti.UI.createWindow({ backgroundColor:arkaplan_sade_ui, title:'News Detail', windowInfo : imagesArray, width:600, navBarHidden:false, barColor:barcolor_ui, }); var baslik = Ti.UI.createLabel({ text:e.source.data,//<<<<< left:0, top:320 }); win_photo.add(baslik); navGroup.open(win_photo,{animated:true}); });
Your Answer
Think you can help? Login to answer this question!