tags:

views:

155

answers:

2

In jqtouch and iui, what do you do if you want to follow a link like <a href="#feed-49">This is a FEED</a> AND dynamically load the content of the <div id="feed-49"></div>?

I've tried bind/live a click handler onto the "a" and onto a parent "div" but it never gets fired, just the event for actually following the link. Thanks.

This is a simplified version of my other question:

http://stackoverflow.com/questions/3506800/jqtouch-mobile-app-ajax-loading-issue

A: 

It depends whether you want the page pre-loaded or load-on-demand.

If you want it pre-loaded, you might want to fill in the page upon, say, $(document).ready:

$(document).ready(function(){
    $('#feed-49').load('feed-49.html');
});

If you want it to load on-demand, you can listen to the pageAnimationStart event:

$('#feed-49').bind('pageAnimationStart', function(event, info){ 
    if (info.direction == 'in') 
        $(this).load('feed-49.html');
});

You may want to read the jQTouch's documentation on callback events.

William
What I needed was to follow that click jqtouch enables with the a-tag but also fire another event -- basically when the user clicks/taps, it should go to the div AND do some other javascript stuff. I finally got it working by adding onClick="other_stuff()"' to the actual a-tag. For some reason live('click',function()... wouldn't work but onClick="" would. Accepting this answer for the combo of your reply and this comment. Thanks for your help.
Hans
your "live()" problem *might* be fixed by upgrading your jquery. I had the similar problem before. :)
William
A: 

I just went through what you are going through and know exactly how to solve it. You need to turn that XML into JSON objects, which will be numbered [0],[1], etc.

This JQuery plugin works and rocks : http://www.fyneworks.com/jquery/xml-to-json/ Add that JS to your app. Your parse XML function will then convert the XML nodes you want (like item nodes within a channel) into JSON objects and then numbers the items.

So look how I then empty the current list of items, build a list of the items and add a custom CLICK function to the list items with a class of "sun" (i love jquery). That function then will add it's parent node title and desc to the divs that need it. The href will push it to the new jqtouch DIV which will handle all the detail info. Cool 'eh? Vote me up if this works. It did for me, like a charm.

function parseXml(xml)
{ 
  $('#feedList').html('');
  var rss = $.xml2json(xml); 
  $.each(rss.channel.item, function(i, item)
    { 
    $('#feedList').empty().append('<li class=sun'+i'><a href=#contentDiv>'+item.title+'</a></li>'); 
    $('.sun'+i).click(function() {
      $('#titleDiv').empty().append(item.title);                
      $('#descDiv').empty().append(item.description);   
      }); 
   }); 
};
B-Money