从 Flex 移动项目中的项目渲染器中调用 navigator.pushView
我希望能够从 cartIncrease 函数调用 navigator.pushView 来更新我的购物车,或者有没有办法重新发出调用渲染器的函数?
这是我的 cartRenderer.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"/>
I would like to be able to call navigator.pushView from the cartIncrease function to update my cart, or is there a way to reissue the function that calls the renderer?
This is my cartRenderer.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>
This is my 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"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过从顶级应用程序中获取相关的 ViewNavigator 解决了这个问题。假设 ViewNavigator 的 id 为“vn”,则为:
I solved this problem by grabbing the relevant ViewNavigator from the top level application. Assuming the ViewNavigator has the id "vn", that would be: