如何在列表视图中环路(客户方来禁用特定复选框) [英] How to loop on the list view (clientside to disable specific check box in)

查看:176
本文介绍了如何在列表视图中环路(客户方来禁用特定复选框)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样一个ListView:

I have a listview like this :

<telerik:RadListView ID="rlv_available_sys" runat="server" ItemPlaceholderID="sys_holder"
                                DataKeyNames="process_id" OnItemDataBound="rlv_available_sys_ItemDataBound">
                                <ItemTemplate>
                                    <table>
                                        <colgroup>
                                            <col title="process name" />
                                        </colgroup>
                                        <tr>
                                            <td>
                                                <asp:HiddenField ID="hf_id" runat="server" Value='<%#Eval("process_id")%>' />
                                                <asp:CheckBox ID="chb_sys" runat="server" CausesValidation="false" />
                                                <asp:Label ID="lbl_available_sys" runat="server" Text='<%# Eval("process_name") %>'></asp:Label>
                                            </td>
                                        </tr>
                                    </table>
                                </ItemTemplate>
                            </telerik:RadListView>


和jQuery的:


and jquery :

addWidgetControls : function () {
        var iNettuts = this,
            $ = this.jQuery,
            settings = this.settings;

        $(settings.widgetSelector, $(settings.columns)).each(function () {
            var thisWidgetSettings = iNettuts.getWidgetSettings(this.id);
            if (thisWidgetSettings.removable) {
                $('<a href="#" class="remove">CLOSE</a>').mousedown(function (e) {
                    e.stopPropagation();    
                }).click(function () {
                    if(confirm('This widget will be removed, ok?')) {
                        $(this).parents(settings.widgetSelector).animate({
                            opacity: 0    
                        },function () {
                            $(this).wrap('<div/>').parent().slideUp(function () {
                                $(this).remove();
                            });
                        });
                    }
                    return false;
                }).appendTo($(settings.handleSelector, this));
            }


我想要做的是:


What i want to do is :

当用户点击接近去除部件,用一些jQuery方式禁用预期的复选框,设置检查= TRUE。(如何修改previous的jQuery在客户端做这个)

When the user click close to remove the widget ,with some jquery way disable the intended check box and set checked = true.(How to modify the previous jquery to do this in client side)

推荐答案

我认为 settings.widgetSelector 选择一个小部件的顶级元素,也就是表或一个Telerik的包装解决它。我离开你的其他code完整:

I assume that settings.widgetSelector selects the top element of a widget, that is, the table or a Telerik wrapper around it. I leave your other code intact:

 ...
 if(confirm('This widget will be removed, ok?')) {
     // reference to current widget wrapper
     var widget = $(this).parents(settings.widgetSelector);
     // disable and select (all) contained checkboxes
     widget.find('input[type=checkbox]').prop({disabled: true, checked: true});​​​​​​​​​​​​​​
     // animate and remove widget...
     widget.animate({
         opacity: 0
     ...

请注意,此解决方案将禁用选择的所有的一个小部件包含复选框。如果你有多个复选框,只需要选择一个单一的,给它一个类(如 myCheckbox ),并选择更改为

Note that this solution will disable and select all contained checkboxes in a widget. If you have multiple checkboxes and only need to select a single one, give it a class (e.g. myCheckbox) and change the selector to

     widget.find('input[type=checkbox].myCheckbox').attr({disabled: true, checked: true});​​​​​​​​​​​​​​

如果你有一个以上的部件,则不应使用现有的复选框ID,如元素ID应该是整个文档独一无二的。

You should not use the existing checkbox ID if you have more than one widget, as element IDs should be unique for the whole document.

更新:

原来是我误解了问题:要禁用的复选框未提到的内部部件和实际任务是

Turned out that I misunderstood the problem: the checkboxes to be disabled are not inside the mentioned widgets and the actual task is to

...禁止输入类型=复选框如果输入型=隐藏中存在的相同的值等于李(部件)的ID

…disable the input type="checkbox" if the value of the input type ="hidden" that exist in the same is equal to the id of the li (widget).

(见注释的讨论。)

这可能是一个解决办法:

This could be a solution:

...
$(settings.widgetSelector, $(settings.columns)).each(function () {
    var widgetId = this.id; 
    var thisWidgetSettings = iNettuts.getWidgetSettings(widgetId);
    if (thisWidgetSettings.removable) {
        $('<a href="#" class="remove">CLOSE</a>').mousedown(function (e) {
            e.stopPropagation();    
        }).click(function () {
            if(confirm('This widget will be removed, ok?')) {
                // Disable checkboxes which have a sibling hidden input field with value equal to widgetId
                $(​'table tr input[type=hidden]').filter(function() {
                    return $(this).val()​​​​​ == widgetId;
                }).siblings('input[type=checkbox]').prop({disabled:true, checked: true});

                // animate and remove widget...
                $(this).parents(settings.widgetSelector).animate({
                    opacity: 0
                ...

这篇关于如何在列表视图中环路(客户方来禁用特定复选框)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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