• SFDC_05(内部类)


    本例主要实现的是前台页面上有复选框,选复选框后把所对应的三条数据留下。

    点击清除复选,就取消复选。

    <apex:page controller="CL_01">
        <apex:form >
            <apex:pageBlock >
                <apex:pageBlockTable value="{!cList}" var="c" columns="3" >
                    <apex:column value="{!c.ac.Id}"/>
                    <apex:column value="{!c.ac.Name}"/>
                    
                    <apex:column headervalue="复选框">
                        <apex:inputCheckbox id="checkbox" value="{!c.check}"/>
                    </apex:column>
                </apex:pageBlockTable>
                <apex:pageblockButtons >
                    <apex:commandButton action="{!clear}" value="清除复选"/>    
                    <apex:commandButton action="{!save}" value="保存"/>
                </apex:pageblockButtons>
            </apex:pageBlock>    
        </apex:form>
    </apex:page>
    public with sharing class CL_01 {
        
        public list<Account> aList{set;get;}
        public list<CL_01DTO> cList{set;get;}
        
        public CL_01(){
            aList = [Select Name, Id From Account];
            cList = new list<CL_01DTO>();
         
            for(Account a : aList){
                CL_01DTO c = new CL_01DTO();
                c.check = false;
                c.ac = a;
                cList.add(c);
              }
        }
        public void save() {
            list<CL_01DTO> cList2 = new list<CL_01DTO>();
            for(CL_01DTO c : cList){
                if(c.check == true){
                    cList2.add(c);
                }
            }
            cList.clear();
            cList = cList2;
        }
        public void clear() {
            for(CL_01DTO c : cList){
                 c.check = false;       
            }
        }
       //定义一个内部类让它有两个属性,一个是check为复选框,一个是Account属性。这样就把复选框和前面的一条数据关联上
       //关键在于前端页面上checkbox 必须加一个属性value 这样才能前后关联上
        public class CL_01DTO{
            public Boolean check{set;get;}
            public Account ac{set;get;}
        }
    }

    如果有更好的方法非常感谢。

  • 相关阅读:
    6 Django的视图层
    5 Django-2的路由层(URLconf)
    4 Django简介
    3 web框架
    2 http协议
    1 web应用
    15-jQuery补充
    14-jQuery的ajax
    13-轮播实现(各种)
    12-事件委托(事件代理)
  • 原文地址:https://www.cnblogs.com/panxing/p/5584291.html
Copyright © 2020-2023  润新知