Вызовите navigator.pushView из средства визуализации элементов в мобильном проекте Flex - PullRequest
1 голос
/ 03 января 2011

Я хотел бы иметь возможность вызвать navigator.pushView из функции cartIncrease, чтобы обновить мою корзину, или есть способ переиздать функцию, которая вызывает средство визуализации?

Это моя корзинаRenderer.mxml

<?xml version="1.0" encoding="utf-8"?>

<fx:Script>
    <![CDATA[
        protected function cartDecrease(item_code:String):void
        {
            // TODO Auto-generated method stub
            trace("cartDecrease: " + item_code);
            removeFromCart("removeFromCart",item_code);
        }

        protected function cartIncrease(item_code:String):void
        {
            // TODO Auto-generated method stub
            trace("cartIncrease: " + item_code);
            addtoCart("addtoCart",item_code);
        }

        protected function addtoCart(fuseaction:String, item_code:String):void
        {
            addtoCartResult.token = rincoMobile.addtoCart(fuseaction, item_code);

        }


        protected function removeFromCart(fuseaction:String, item_code:String):void
        {
            removeFromCartResult.token = rincoMobile.removeFromCart(fuseaction, item_code);
        }

    ]]>
</fx:Script>
<fx:Declarations>
    <s:CallResponder id="addtoCartResult"/>
    <rincomobile:RincoMobile id="rincoMobile"/>
    <s:CallResponder id="removeFromCartResult"/>
</fx:Declarations>


<!-- cart info wrapper -->
<s:Group width="100%" height="100%">

    <!-- background box -->
    <s:Rect width="100%" height="100%">
        <s:fill>
            <s:SolidColor color="#ffffff"/>
        </s:fill>
    </s:Rect>

    <!-- cart info -->
    <s:VGroup 
        width="100%" height="100%"
        horizontalAlign="right"
        paddingBottom="10"
        paddingLeft="10"
        paddingRight="10"
        paddingTop="10"
        gap="18">


        <!-- total -->
        <s:Group width="100%">
            <s:layout>
                <s:HorizontalLayout  verticalAlign="justify"/>
            </s:layout>

            <!-- thumb and item_code -->
            <s:Group width="100">
                <s:layout>
                    <s:VerticalLayout  horizontalAlign="center" />
                </s:layout>
                <s:Image source="{data.thumb_url}" width="100" height="100" />
                <s:Label width="100" color="#000000" fontSize="12" fontWeight="bold"
                         text="{data.item_code}" textAlign="center"/>
            </s:Group>
            <!-- 
            <s:Label text="{data.qty}" width="50" color="#000000" fontSize="12" fontWeight="bold"/>
            -->
            <s:Group width="100%">
                <s:layout>
                    <s:VerticalLayout horizontalAlign="justify" />
                </s:layout>
                <s:Label text="{data.item_description}" width="100%" color="#1D4C93" fontSize="14" fontWeight="bold" />
                <s:Label text="{data.qty} x {data.unit_price} = {data.price}" width="50" color="#FF0000" fontSize="16" fontWeight="bold" />

                <s:Group width="150" textAlign="right">
                    <s:layout>
                        <s:HorizontalLayout columnWidth="65" gap="10" paddingRight="0"
                                            variableColumnWidth="false" verticalAlign="justify"/>
                    </s:layout>
                    <s:Button width="63" height="63" label="-" color="#FFFFFF" fontSize="30"
                              fontWeight="bold" horizontalCenter="1" click="cartDecrease(data.item_code)" />
                    <s:Button width="63" height="63" label="+" color="#FFFFFF" fontSize="23"
                              fontWeight="bold" click="cartIncrease(data.item_code)"/>
                </s:Group>        
            </s:Group>

        </s:Group>
    </s:VGroup>

    <!-- vertical divider -->
    <s:Rect width="1" height="100%">
        <s:fill>
            <s:SolidColor color="0xBFBFBF"/>
        </s:fill>
    </s:Rect>
</s:Group>

Это мой view_cart.mxml

<?xml version="1.0" encoding="utf-8"?>

        import mx.events.FlexEvent;

        // protected functions
        protected function list_creationCompleteHandler(event:FlexEvent):void {
            getCartResult.token = rincoMobile.getCart("getCart");
            getCartTotalResult.token = rincoMobile.getCartTotal("getCartTotal");
        }

        protected function getCartTotal(fuseaction:String):void {
            getCartTotalResult.token = rincoMobile.getCartTotal(fuseaction);
        }

        protected function button1_clickHandler(event:MouseEvent):void {
            // go back to original view
            navigator.popView();
        }

        protected function btn_checkout_clickHandler(event:MouseEvent):void {
            trace("pushView - view_CheckOut");
            navigator.pushView(view_CheckOut);

        }

        protected function clearCart(fuseaction:String):void
        {
            clearCartResult.token = rincoMobile.clearCart(fuseaction);
            navigator.pushView(view_rincoMobileHome); 
        } 


        protected function button2_clickHandler(event:MouseEvent):void
        {
            clearCart("clearCart");

        }

        public function refresh():void {
            getCartResult.token = rincoMobile.getCart("getCart");
            getCartTotalResult.token = rincoMobile.getCartTotal("getCartTotal");
        }
    ]]>
</fx:Script>
<fx:Declarations>
    <s:CallResponder id="getCartResult"/>
    <rincomobile:RincoMobile id="rincoMobile" />
    <s:CallResponder id="getCartTotalResult"/>
    <s:CallResponder id="clearCartResult"/>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:List id="list" left="0" right="0" top="0" bottom="176" borderVisible="false"
        creationComplete="list_creationCompleteHandler(event)"
        itemRenderer="renderers.cartRenderer" labelField="item_code">
    <s:AsyncListView list="{TypeUtility.convertToCollection(getCartResult.lastResult.cart)}"/>
</s:List>
<s:Button id="btn_checkout" bottom="89" width="432" label="${getCartTotalResult.lastResult.cart[0].total}  Checkout" chromeColor="#091A33" horizontalCenter="0" click="btn_checkout_clickHandler(event)" />
<s:Button bottom="18" width="200" label="Continue Shopping" chromeColor="#091A33"
          click="button1_clickHandler(event)" fontSize="15" horizontalCenter="-116"/>
<s:Button bottom="18" width="218" label="Clear Cart" chromeColor="#091A33"
          click="button2_clickHandler(event)" fontSize="15" horizontalCenter="107"/>

1 Ответ

3 голосов
/ 15 июля 2011

Я решил эту проблему, взяв соответствующий ViewNavigator из приложения верхнего уровня. Предполагая, что ViewNavigator имеет идентификатор "vn", это будет:

this.parentApplication.vn.pushView(MyViewClass);
...