无法在phonegap android应用程序中通过JSON响应添加选项

时间:2013-10-23 11:48:10

标签: javascript android json cordova

我正尝试在json response中的应用程序的下拉列表(select)中添加选项。

这是我的JSON回复:

{"Value":[{"Sub_Bhav_Copy_Name":"All","Sub_Bhav_id":"0"},{"Sub_Bhav_Copy_Name":"COC Prices","Sub_Bhav_id":"2"},{"Sub_Bhav_Copy_Name":"Cotton Price","Sub_Bhav_id":"4"},{"Sub_Bhav_Copy_Name":"Kapas Prices","Sub_Bhav_id":"1"},{"Sub_Bhav_Copy_Name":"Yarn Prices","Sub_Bhav_id":"3"}]}

这是我的js代码:

function callcottonVarUrl(url) {
    $.ajax({
        url: url,
        type : "GET",
        dataType : "json",
        contentType: "application/json",
        async : false,
        success : function(msg) {
            jsonRespCtnVar = msg.Value;
            alert(jsonRespCtnVar);
            $("#CategorySelection option").remove();
            $.each(jsonRespFav, function(index, value) {
                cottonVarName = value.Sub_Bhav_Copy_Name;
                cottonVarId = value.Sub_Bhav_id;
                $jsonRespCtnVar = '<option value="'+cottonVarId+'">'+cottonVarName+'</option>';
                $('#CategorySelection').append($jsonRespCtnVar);
            });
        },
        error : function(msg) {
            alert ("error occured");
        }
    });
}

这是.html:

    <div id="searchbg">
                    <span>SEARCH&nbsp;COTTON</span>
                    <p id="selectcontainer">
                        <b></b>
                        <select id="CategorySelection" data-native-menu="true" name="" onChange="changetextbox()">
<!--                                <option value="">Please Select Cotton Type</option>       -->
                            </select></p>
                    <div id="search">
                            <input name="" id="searchBox" type="text"
                            placeholder="Enter Commodity"> <a href="#"
                            class="greenbtn" id="button" type="submit"><span class=" sprite"></span></a>

                    </div>

但是当我测试它时,下拉列表中没有生成任何选项。 不知道原因。任何帮助?

0 个答案:

没有答案