将数组数据添加到变量

发布于 2024-12-09 12:59:55 字数 6639 浏览 0 评论 0原文

我有一个应用程序当前从 facebook 获取事件数据并将其显示到列表中

<s:List id="eventsDataGrid" width="100%" height="100%" dataProvider="{facebookEvents}">
        <s:itemRenderer>
            <fx:Component>
                <s:ItemRenderer>
                    <fx:Script>
                        <![CDATA[
                            import com.facebook.graph.utils.FacebookDataUtils;
                            private function time2DateStr(time:String):String {
                                return FacebookDataUtils.stringToDate(time).toLocaleString();
                            }

                        ]]>
                    </fx:Script>
                    <s:HGroup paddingBottom="10" paddingTop="10">
                        <s:Image source="{data.pic}"/>
                        <s:VGroup width="100%">
                            <s:Label text="{data.name}" fontWeight="bold" width="100%"/>
                            <s:Label text="Where: {data.location}" id="locationtxt"/>
                            <s:Label text="When: {time2DateStr(data.start_time)}"/>

                        </s:VGroup>
                    </s:HGroup>
                </s:ItemRenderer>
            </fx:Component>
        </s:itemRenderer>
        </s:List>

我正在尝试添加一个按钮,该按钮将在 webView 中显示位置,但我无法让该应用程序使用要使用的数组中的 data.location它与谷歌地图(我只是将 data.location 详细信息添加到谷歌地图 URL 的末尾,然后该 URL 将使用地图来搜索位置 我可以让按钮工作,但它不会搜索位置,它只是在 flash builder 中显示错误(我认为这是因为我没有正确地将数据添加到字符串中)或搜索“data.location” 这是当前的代码,将加载 URL,但没有位置

        <s:List id="eventsDataGrid" width="100%" height="100%" dataProvider="{facebookEvents}">
        <s:itemRenderer>
            <fx:Component>
                <s:ItemRenderer>
                    <fx:Script>
                        <![CDATA[
                            import com.facebook.graph.utils.FacebookDataUtils;
                            var webView:StageWebView = new StageWebView
                            var mapURL:String = "http://maps.google.com/maps?f=d&hl=en&saddr="
                            private function time2DateStr(time:String):String {
                                return FacebookDataUtils.stringToDate(time).toLocaleString();
                            }

                            protected function getDirections_clickHandler(event:MouseEvent):void
                            {
                                webView.stage = this.stage;
                                webView.viewPort = new Rectangle(0, 100, stage.stageWidth, stage.stageHeight);
                                webView.loadURL(mapURL);    
                            }

                        ]]>
                    </fx:Script>
                    <s:HGroup paddingBottom="10" paddingTop="10">
                        <s:Image source="{data.pic}"/>
                        <s:VGroup width="100%">
                            <s:Label text="{data.name}" fontWeight="bold" width="100%"/>
                            <s:Label text="Where: {data.location}" id="locationtxt"/>
                            <s:Label text="When: {time2DateStr(data.start_time)}"/>
                            <s:Label text="Get Directions" click="getDirections_clickHandler(event)" id="getDirections"/>
                        </s:VGroup>
                    </s:HGroup>
                </s:ItemRenderer>
            </fx:Component>
        </s:itemRenderer>
        </s:List>

完整代码

<fx:Script>
<![CDATA[
    import mx.collections.ArrayCollection;
    [Bindable] private var facebookEvents:ArrayCollection;
    import com.facebook.graph.FacebookMobile;
    private function onLoad():void
    {
        if(FacebookMobile.getSession() != null) {
            getEvents()
        } else {
            eventsDataGrid.visible=false
            NotLogin.visible=true
        }

    }

    private function getEvents():void {
        var fql:String = "select name, location, pic, start_time from event where creator = 148839887036 and eid in (select eid from event_member where uid=148839887036)";
        FacebookMobile.fqlQuery(fql, handleGetEventsResponse);
    }

    private function handleGetEventsResponse(events:Object, fail:Object):void {
        if (events != null)
            facebookEvents = new ArrayCollection(events as Array);
        //else
            //status = "Error";
    }   
]]>

    <s:List id="eventsDataGrid" width="100%" height="100%" dataProvider="{facebookEvents}">
        <s:itemRenderer>
            <fx:Component>
                <s:ItemRenderer>
                    <fx:Script>
                        <![CDATA[
                            import com.facebook.graph.utils.FacebookDataUtils;
                            var webView:StageWebView = new StageWebView
                            var mapURL:String = "http://maps.google.com/maps?f=d&hl=en&saddr="
                            private function time2DateStr(time:String):String {
                                return FacebookDataUtils.stringToDate(time).toLocaleString();
                            }

                            protected function getDirections_clickHandler(event:MouseEvent):void
                            {
                                webView.stage = this.stage;
                                webView.viewPort = new Rectangle(0, 100, stage.stageWidth, stage.stageHeight);
                                webView.loadURL(mapURL);    
                            }

                        ]]>
                    </fx:Script>
                    <s:HGroup paddingBottom="10" paddingTop="10">
                        <s:Image source="{data.pic}"/>
                        <s:VGroup width="100%">
                            <s:Label text="{data.name}" fontWeight="bold" width="100%"/>
                            <s:Label text="Where: {data.location}" id="locationtxt"/>
                            <s:Label text="When: {time2DateStr(data.start_time)}"/>
                            <s:Label text="Get Directions" click="getDirections_clickHandler(event)" id="getDirections"/>
                        </s:VGroup>
                    </s:HGroup>
                </s:ItemRenderer>
            </fx:Component>
        </s:itemRenderer>
        </s:List>

I have a app that currently gets event data from facebook and displays this into a list

<s:List id="eventsDataGrid" width="100%" height="100%" dataProvider="{facebookEvents}">
        <s:itemRenderer>
            <fx:Component>
                <s:ItemRenderer>
                    <fx:Script>
                        <![CDATA[
                            import com.facebook.graph.utils.FacebookDataUtils;
                            private function time2DateStr(time:String):String {
                                return FacebookDataUtils.stringToDate(time).toLocaleString();
                            }

                        ]]>
                    </fx:Script>
                    <s:HGroup paddingBottom="10" paddingTop="10">
                        <s:Image source="{data.pic}"/>
                        <s:VGroup width="100%">
                            <s:Label text="{data.name}" fontWeight="bold" width="100%"/>
                            <s:Label text="Where: {data.location}" id="locationtxt"/>
                            <s:Label text="When: {time2DateStr(data.start_time)}"/>

                        </s:VGroup>
                    </s:HGroup>
                </s:ItemRenderer>
            </fx:Component>
        </s:itemRenderer>
        </s:List>

I am trying to add a button that will display the location in a webView but i can not get the app to use the data.location from the array to use it with Google maps (i am just adding the data.location details to the end of a Google maps URL which will then use maps to search for the location
I can get the button to work but it will not search for the location it just either displays an error in flash builder (which i assume is down to me not adding the data to the string correctly) or searches for "data.location"
Here is the current code that will load the URL but with no location

        <s:List id="eventsDataGrid" width="100%" height="100%" dataProvider="{facebookEvents}">
        <s:itemRenderer>
            <fx:Component>
                <s:ItemRenderer>
                    <fx:Script>
                        <![CDATA[
                            import com.facebook.graph.utils.FacebookDataUtils;
                            var webView:StageWebView = new StageWebView
                            var mapURL:String = "http://maps.google.com/maps?f=d&hl=en&saddr="
                            private function time2DateStr(time:String):String {
                                return FacebookDataUtils.stringToDate(time).toLocaleString();
                            }

                            protected function getDirections_clickHandler(event:MouseEvent):void
                            {
                                webView.stage = this.stage;
                                webView.viewPort = new Rectangle(0, 100, stage.stageWidth, stage.stageHeight);
                                webView.loadURL(mapURL);    
                            }

                        ]]>
                    </fx:Script>
                    <s:HGroup paddingBottom="10" paddingTop="10">
                        <s:Image source="{data.pic}"/>
                        <s:VGroup width="100%">
                            <s:Label text="{data.name}" fontWeight="bold" width="100%"/>
                            <s:Label text="Where: {data.location}" id="locationtxt"/>
                            <s:Label text="When: {time2DateStr(data.start_time)}"/>
                            <s:Label text="Get Directions" click="getDirections_clickHandler(event)" id="getDirections"/>
                        </s:VGroup>
                    </s:HGroup>
                </s:ItemRenderer>
            </fx:Component>
        </s:itemRenderer>
        </s:List>

FULL CODE

<fx:Script>
<![CDATA[
    import mx.collections.ArrayCollection;
    [Bindable] private var facebookEvents:ArrayCollection;
    import com.facebook.graph.FacebookMobile;
    private function onLoad():void
    {
        if(FacebookMobile.getSession() != null) {
            getEvents()
        } else {
            eventsDataGrid.visible=false
            NotLogin.visible=true
        }

    }

    private function getEvents():void {
        var fql:String = "select name, location, pic, start_time from event where creator = 148839887036 and eid in (select eid from event_member where uid=148839887036)";
        FacebookMobile.fqlQuery(fql, handleGetEventsResponse);
    }

    private function handleGetEventsResponse(events:Object, fail:Object):void {
        if (events != null)
            facebookEvents = new ArrayCollection(events as Array);
        //else
            //status = "Error";
    }   
]]>

    <s:List id="eventsDataGrid" width="100%" height="100%" dataProvider="{facebookEvents}">
        <s:itemRenderer>
            <fx:Component>
                <s:ItemRenderer>
                    <fx:Script>
                        <![CDATA[
                            import com.facebook.graph.utils.FacebookDataUtils;
                            var webView:StageWebView = new StageWebView
                            var mapURL:String = "http://maps.google.com/maps?f=d&hl=en&saddr="
                            private function time2DateStr(time:String):String {
                                return FacebookDataUtils.stringToDate(time).toLocaleString();
                            }

                            protected function getDirections_clickHandler(event:MouseEvent):void
                            {
                                webView.stage = this.stage;
                                webView.viewPort = new Rectangle(0, 100, stage.stageWidth, stage.stageHeight);
                                webView.loadURL(mapURL);    
                            }

                        ]]>
                    </fx:Script>
                    <s:HGroup paddingBottom="10" paddingTop="10">
                        <s:Image source="{data.pic}"/>
                        <s:VGroup width="100%">
                            <s:Label text="{data.name}" fontWeight="bold" width="100%"/>
                            <s:Label text="Where: {data.location}" id="locationtxt"/>
                            <s:Label text="When: {time2DateStr(data.start_time)}"/>
                            <s:Label text="Get Directions" click="getDirections_clickHandler(event)" id="getDirections"/>
                        </s:VGroup>
                    </s:HGroup>
                </s:ItemRenderer>
            </fx:Component>
        </s:itemRenderer>
        </s:List>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

誰ツ都不明白 2024-12-16 12:59:55

我需要做的就是将数据添加到括号中(不知道正式名称),这里是

protected function directions_click (location:String):void
{
  navigateToURL(new URLRequest('http://maps.google.co.uk/maps?q=' + location));
}

按钮/标签

<s:Label text="Get Directions" fontFamily="lucida grande" fontSize="14" color="#3b5998" click="directions_click(data.location)"/>

all i needed to do was to add the data into the brackets (dont know the offical name) here it is

protected function directions_click (location:String):void
{
  navigateToURL(new URLRequest('http://maps.google.co.uk/maps?q=' + location));
}

and for the button/ label

<s:Label text="Get Directions" fontFamily="lucida grande" fontSize="14" color="#3b5998" click="directions_click(data.location)"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文