English 中文(简体)
jQuery.data() works in Mac OS WebKit, but not on iPhone OS?
原标题:

I m playing around with jQTouch for an iPhone OS app that I ve been toying with off and on for a while. I wanted to try my hand building it as a web app so I started playing with jQTouch. For reference, here is the page+source (all my code is currently in index.html so you can just "View Source" to see it all):

http://rpj.me/doughapp.com/wd/

Essentially, I m trying to save pertinent JSON objects retrieved from Google Local into DOM objects using the data() method (in this example, obj is the Google Local object):

$( #locPane ).data( selected , obj);

then later (in a different "pane"), retrieving that object to be used:

$( #locPane ).bind( pageAnimationEnd , function(e, inf) {
            var selobj = $(this).data( selected );
            // use  selobj  here ...
}

In Chromium and Safari on the desktop OS (Snow Leopard in my case), this works perfectly (try it out).

However, the same code returns undefined for the call to $(this).data( selected ) in the second snippet above. I ve also tried $( # + e.target.id).data( selected ) and even the naive $( #locPane ).data( selected ). All variants return undefined in the iPhone OS version of WebKit, but not on the desktop.

Interestingly, the running this on Mobile Safari in the iPhone Simulator fails as well.

If you look at the full source, you ll see that I even try to save this object into my global jQTouch object (named jqt in my code). This, too, fails on the mobile platform.

Has anyone else ever ran into this? I ll admit to not being a web/javascript programmer by trade, so if I m making an idiot s error please call me out on it.

Thank you in advance for the help! -RPJ

Update: I didn t make it clear in the original post, but I m open to any workaround if it works consistently. Since I m having trouble storing these objects in general, anything that allows me to keep them around is good enough for now. Thanks!

问题回答

Have you tried using HTML5 data-ref attributes? The data has to be stringified, but you can just do

$( #locPane ).attr( data-selected , "somestring");

and still have valid HTML5 markup.

As far as I can tell there seems to be a bug in Mobile Safari storing objects like this. So what I did was to simply store the components of the object in the documents data store.

 $(document).data( "lessonCode" , lesson.lessonCode);
 $(document).data( "question" , lesson.question);
 $(document).data( "answer" , lesson.answer);




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签