0

I would like to be able to identify and process link meta data with live events. So if I have a link like so:

<a href="#workorder_new" data-city="austin" data-state="tx">Click here</a>

Somehow I need to get the above element (specifically data attributes) into the "live" function and then call on a Javascript function, with jQuery-mobile live elements, something like:

$('[href=#workorder_new]').live('click', function()
{
  var target        = $(this);
  var workorder_new = new workorder_new_controller(target.data);

  $('#workorder_new').bind('pagebeforechange',function(event, ui)
  {
    workorder_new.before();
  });

  $('#workorder_new').bind('pageshow',function(event, ui)
  {
    // var page = event.target.id;
    workorder_new.after();
  });
});

function workorder_new_controller(data)
{
  var city  = data.city;
  var state = data.state;

  this.before = function(){
    // console.log(data);
  }
  this.after  = function(){
    // console.log(data);
    var today    = new Date();
    var tomorrow = new Date(today.getTime() + (24 * 60 * 60 * 1000));
    $('#workorder_new_form [name=due_date]').val(readable_date(tomorrow));
  }
}

So this is just some code I'm playing around with right now trying to piece it together. But I think I'm way off course here. Could somebody lend some advice for how I could get this working as expected? Or at least some tips to get me on the right path? Thanks!

4

2 に答える 2

0

理解した:

var params = {};

$('a').live('click', function(event)
{
  $.each($(event.target)[0].attributes, function(key, value){
    params[value.name] = value.value;
  });
});

$('div[data-role="page"]').live('pageshow',function(event, ui)
{
 console.log(params)
});

ソース: http: //moorberry.net/blog/link-attributes-jquery-mobile/

于 2013-02-07T01:14:44.413 に答える
0
var target = $(this);
var city = target.data('city');
var state = target.data('state');

jQueryのバージョンに応じて、に変更.liveする必要があります.onが、それは関係ありません。

于 2013-02-05T02:25:11.977 に答える