BlackBerry 10 Cascades: How do I load data into a DropDown?

只谈情不闲聊 提交于 2019-12-04 19:21:10

I have an alternate method for you, Do note that I have used google's web service here for demonstration purpose, you need to replace it with your url & parse response according to that.

import bb.cascades 1.0

Page {
    attachedObjects: [
        ComponentDefinition {
            id: optionControlDefinition
            Option {
            }
        }
    ]
    function getData() {
        var request = new XMLHttpRequest()
        request.onreadystatechange = function() {
            if (request.readyState == 4) {
                var response = request.responseText
                response = JSON.parse(response)
                var addressComponents = response.results[0].address_components
                for (var i = 0; i < addressComponents.length; i ++) {
                    var option = optionControlDefinition.createObject();
                    option.text = addressComponents[i].long_name
                    dropDown.add(option)
                }
            }
        }

        // I have used goole's web service url, you can replace with your url
        request.open("GET", "http://maps.googleapis.com/maps/api/geocode/json?address=" + "Ahmedabad" + "&sensor=false", true)
        request.send()
    }
    Container {
        DropDown {
            id: dropDown
        }
        Button {
            onClicked: getData()
        }
    }
}

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!