Event handlers in Repeater components

本文介绍了一种使用Flex实现按钮动态导航的方法。通过Repeater组件和ArrayCollection数据绑定,为每个按钮分配不同的URL链接,当用户点击按钮时,将打开对应的网页。
<?xml version="1.0"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script> 
        <![CDATA[
             public function clicker(cName:String):void { 
                  foolabel.text=cName; 
             }    
        ]]>
    </mx:Script> 

    <mx:Label id="foolabel" text="foo"></mx:Label> 
 
    <mx:Model id="data"> 
        <color>
            <colorName>Red</colorName> 
            <colorName>Yellow</colorName> 
            <colorName>Blue</colorName>
        </color>
    </mx:Model> 
    <mx:ArrayCollection id="myAC" source="{data.colorName}"/>

    <mx:Repeater id="myrep" dataProvider="{myAC}"> 
        <mx:Button click="clicker(event.currentTarget.getRepeaterItem());"
            label="{myrep.currentItem}"/> 
    </mx:Repeater> 
</mx:Application>

After the user clicks the Yellow button, the application looks like this:


The code in the following example uses the getRepeaterItem() method to display a specific URL for each Button control that the user clicks. The Button controls must share a common data-driven click handler, because you cannot use binding expressions inside event handlers. However, the getRepeaterItem() method lets you change the functionality for each Button control.

<?xml version="1.0"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        <![CDATA[
            [Bindable]
            public var dp:Array = [ { label: "Flex",
                url: "http://www.adobe.com/flex" },
                { label: "Flash", url: "http://www.adobe.com/flash" } ];
        ]]>
    </mx:Script>

    <mx:ArrayCollection id="myAC" source="{dp}"/>
    <mx:Repeater id="r" dataProvider="{myAC}">
        <mx:Button label="{r.currentItem.label}" click="navigateToURL(new
            URLRequest(event.currentTarget.getRepeaterItem().url));"/>
    </mx:Repeater>
</mx:Application>

When executed, this example yields two buttons: one for Flex and one for Flash. When you click the button of your choice, the relevant product page loads in a new browser window.


<script type="text/javascript"></script>

在前端开发中,Ajax(Asynchronous JavaScript and XML)是一种用于创建快速动态网页的技术。它允许网页在不重新加载整个页面的情况下与服务器交换数据和更新部分网页内容。Global Ajax Event Handlers指的是可以全局捕获所有Ajax请求和响应的事件处理程序。 以下是一些常见的Global Ajax Event Handlers: 1. `ajaxStart`: 当一个Ajax请求开始时触发。可以用来显示一个加载动画或者禁用某些按钮,防止用户在请求完成前重复提交。 2. `ajaxStop`: 当所有的Ajax请求都完成时触发。可以用来隐藏加载动画或者重新启用之前被禁用的按钮。 3. `ajaxError`: 当任何一个Ajax请求出错时触发。可以用来显示错误信息给用户,或者记录错误日志以便调试。 4. `ajaxSuccess`: 当任何一个Ajax请求成功完成时触发。可以用来执行一些通用的成功处理逻辑,比如清除表单、重置状态等。 5. `ajaxComplete`: 无论Ajax请求成功还是失败,只要请求完成就会触发。可以用来执行一些清理工作,比如移除临时数据、恢复界面元素等。 这些事件处理程序可以通过jQuery库来轻松设置,例如: ```javascript $(document).ajaxStart(function() { console.log('Ajax request started'); }); $(document).ajaxStop(function() { console.log('All Ajax requests completed'); }); $(document).ajaxError(function(event, jqXHR, settings, exception) { console.error('An Ajax error occurred:', exception); }); $(document).ajaxSuccess(function(event, jqXHR, settings) { console.log('Ajax request succeeded'); }); $(document).ajaxComplete(function(event, jqXHR, settings) { console.log('Ajax request completed'); }); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值