1

我现在正在使用 Phonegap Cordova 2.0.0 和 Jquery Mobile 1.1.1 final 实现 Windows Phone,由于 Window Phone Emulator 没有将 JSON 数据加载到<select>元素,而 iOS 和 Android 模拟器都运行顺利,我一直坚持使用本地 JSON 文件. 这是我的代码片段

<!DOCTYPE html> 
<html> 
    <head> 
        <title>Page Title</title> 

        <meta name="viewport" content="width=device-width, initial-scale=1"> 
        <link rel="stylesheet" href="css/jquery.mobile-1.1.1.min.css" />
        <link rel="stylesheet" href="css/jqm-icon-pack-2.1.2-fa.css" />
        <script type="text/javascript" src="js/cordova-2.0.0.js"></script>
        <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
        <script type="text/javascript" src="js/jquery.mobile-1.1.1.min.js"></script>
        <script type="text/javascript" src="js/json2.js"></script>
        <script type="text/javascript" charset="utf-8">

            function changeBaseAmount() {
                alert($('#baseAmount').val());
            }

        $.getJSON('json/currencies.json',
            function (data) {
                alert("get json");
                $.each(data, function (key, value) {

                    $('#currency1').append("<option value='" + key + "'>" + value + "</option>");

                    $('#currency2').append("<option value='" + key + "'>" + value + "</option>");

               });

           });



    </script>
    </head> 

    <body> 
        <!-- Home Page -->
        <div data-role="page" data-theme="b">
            <div data-role="header" data-theme="b">

                <h1>Convert Currency</h1>
                <a href="#" data-role="button" data-icon="wrench" data-iconpos="notext"></a>
            </div> 

            <div data-role="content" data-theme="b">

                <div id="baseAmountDiv" data-role="fieldcontain">
                    <label for="baseAmount">Amount:</label>
                    <input id="baseAmount" type="text" value="" onchange="changeBaseAmount()"></input>
                </div>
                <div id="currency1Div" data-role="fieldcontain">
                    <label for="currency1">Currency From:</label>
                    <select id="currency1" onchange="changeCurrency1()">
                        <option value="ZZ">Please Select Currency From</option>
                    </select>
                </div>
                <div id="currency2Div" data-role="fieldcontain">
                    <label for="currency2">Currency To:</label>
                    <select id="currency2" onchange="changeCurrency2()">
                        <option value="ZZ">Please Select Currency To</option>
                    </select>
                </div>
                <div id="resultAmountDiv" data-role="fieldcontain">
                    <label for="resultAmount">Result:</label>
                    <input id="resultAmount" type="text" value="" readonly="readonly" style="background-color: silver"></input>
                </div>
            </div> 

            <div data-role="footer" data-theme="b"></i></div> 
        </div>
    </body>
</html>
4

1 回答 1

0

WP7 的 Cordova 有自己的 XHR 请求实现,以支持获取本地数据。请参阅以下内容:

https://issues.apache.org/jira/browse/CB-208

您可能必须使用$.ajax它才能正常工作。

于 2012-07-30T10:01:15.357 回答