如何使用phonegap和jquery mobile在iphone模拟器中进行链接?

时间:2013-07-29 14:47:55

标签: jquery-mobile cordova

我正在使用Phonegap / cordova和jquery mobile。当我在chrome浏览器中运行以下代码时,它按预期工作。但是,当我构建应用程序并尝试在Xcode iPhone模拟器中运行它时,我遇到了问题。第一页(解析json +显示结果)工作正常,但我无法点击该项目并转到详细信息页面。关于如何解决这个问题的任何建议?

<!DOCTYPE html>
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
         <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css">
           <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> 
           <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
           <meta name="viewport" content="width=device-width, initial-scale=1">

            <style>
                .custom_listview_img {
                    margin:0px; 
                    padding:0px;
                    background-repeat:no-repeat;
                    background-size:100%;
                    height:150px;
                }
                ul {list-style : none; padding:0px;}
            </style>

            <script>
                $(document).on('click','.changePageButton', function() {
                    $.mobile.changePage("#page2");
                });
            </script>

            <script type="text/javascript">

      $(document).ready(function(){
        var url='http://api.yipit.com/v1/deals/?key=mRSTBQsB49CdMXTW&division=san-francisco&tag=restaurants&lat=37.871087&lon=-122.270913&callback=?';

            $.getJSON(url,function(json){
              $.each(json.response.deals,function(i,item){

                 $("#results").append('<ul data-role="listview" data-inset="true" data-theme="d" data-divider-theme="a" style="white-space:normal"><a class = "changePageButton" data-transition="slide"><li data-role="list-divider" role="heading" class="ui-li ui-li-divider ui-btn ui-bar-c ui-corner-top">'+item.business.name+'</li><li class="custom_listview_img" style = "background-image:url('+item.images.image_smart+');"></li></a></ul>');

              });
            });   

      });

    </script>
        <title>Hello</title>
    </head>
    <body>
            <div data-role="page" data-theme="c"> 

            <div data-role="header" data-theme="b"> 
                   <h1>Dealoka</h1> 
            </div> 

             <div data-role="content" id = "results">
                <!-- Display results of parsing json here -->
             </div>   

        </div> 



    <div data-role="page" id="page2" data-add-back-btn="true">
       <div data-role="header" data-theme="b">
          <h1>Page 2</h1>
       </div>
       <div data-role="content">
          <p>Deal details</p>
       </div> 
    </div>

        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript">
            app.initialize();
        </script>
    </body>
</html>

1 个答案:

答案 0 :(得分:0)

您可以使用vclick事件代替click

详细信息: http://api.jquerymobile.com/vclick/