BlackBerry 10 Cascades:如何将数据加载到 DropDown 中? [英] BlackBerry 10 Cascades: How do I load data into a DropDown?

查看:23
本文介绍了BlackBerry 10 Cascades:如何将数据加载到 DropDown 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已设法将远程 Json Web 服务中的数据加载到 QML ListView 中,但 DropDown 控件似乎没有任何此类内容.

I have managed to load data from a remote Json web service into a QML ListView, but there doesn't seem to be any such thing for the DropDown control.

有人有示例或替代方法来完成绑定到 Cascades 中附加对象数据源的 DropDown 吗?

Does someone have an example or an alternative method to accomplish a DropDown bound to attachedObjects data sources in Cascades?

推荐答案

我有一个替代方法给你,请注意我在这里使用了谷歌的网络服务用于演示目的,你需要将它替换为你的 url &据此解析响应.

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()
        }
    }
}

希望这会有所帮助.

这篇关于BlackBerry 10 Cascades:如何将数据加载到 DropDown 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆