在开发过程中,往往需要利用数据动态生成Checkbox。如权限节点。考试答案,调查选项等等。在Extjs中,有两种方法来获取后台数据,一是Ext.Ajax()方法,第二种是利用 Store,store其实也是利用ajax方式来获取,下面以利用Store的方式来实现动态生成。

1、定义Store

       //定义store
var customFieds = new Ext.data.Store({
url: ‘Controls/GetFields',
remoteSort: true,
reader: new Ext.data.JsonReader({
root: 'data',
totalProperty: 'total',
id: 'Id'
}, [
{ name: 'Id', type: 'string' },
{ name: 'Name', type: 'string' },
{name: 'FieldType', type: 'string'},
{name: 'IsChecked', type: 'string'}
])
});

2、生成

/**
* 生成Checkbox
*
*/
function generateCheckbox() { //以store动态生成Checkbox
var items = [];
for (var i = 0; i < customFieds.getCount(); i++) {
var d = customFieds.getAt(i);
var chk = { id: d.get('Id'), boxLabel: d.get('Name'), name: 'LableFields',inputValue:d.get('Id'),checked :d.get('IsChecked')=='true'?true:false };
items.push(chk);
}
var CheckBoxGroupTypes = new Ext.form.CheckboxGroup({
xtype: 'checkboxgroup',
fieldLabel: 'Field<span style="color: red;" >*</span>',
id: 'Field',
allowBlank: false,
name: 'LableFields',
columns: 3,
anchor: "95%",
msgTarget: "side"
});
CheckBoxGroupTypes.items = items;
var singleColumn1 = [
CheckBoxGroupTypes
]; var form = new Ext.FormPanel({
border: false,
waitMsgTarget: true,
labelWidth: 100,
frame: true,
fileUpload: true,
bodyStyle: 'padding:5px 5px 0',
labelAlign: 'right',
items: singleColumn1,
buttonAlign: 'center',
buttons: [new Ext.ux.SubmitBtn({
text: 'Submit.',
handler: function() {
if (form.getForm().isValid()) {
form.getForm().submit({
url: 'Control/SaveOrUpdate',
params: {
"Id": id
},
waitMsg: 'save...',
timeout: 2000 * 1000,
success: function (form, action) {
if (action.result.success) {
win.destroy();
FieldRuleStore.load({ params: {
start: 0,
limit: ALL_PAGESIZE_SETTING
}
});
}
},
failure: function (form, action) {
Ext.Msg.show(action.result.msg); }
});
}
}
}), new Ext.ux.CancelBtn({
text: 'Exit',
handler: function() {
win.destroy();
}
})]
});
var win = new Ext.Window({
id: ‘id',
title: title,
iconCls: 'application_form',
width: 500,
resizable: false,
constrain: true,
autoHeight: true,
modal: true,
closeAction: 'close',
plain: true,
items: [form]
});
win.show(); }

3、回调生成,回调的原因是因为extjs store获取数据是使用ajax方式获取。回调就是要在获取数据成功后才动态生成。

customFieds.load({
params: {
Id:id
},
callback: function(r, option, sucess)
{ generateCheckbox(); }
});

4、效果图

ExtJs 3.0 动态生成 CheckBox的更多相关文章

  1. 动态生成CheckBox(Winform程序)

    在做用户权限设置功能时,需要做一个动态生成权限列表的功能.(笔记.分享) //1.清空权限控件组的默认控件 panelPermissions.Controls.Clear(); _groupBoxLi ...

  2. jquery控制动态生成的gridview中多列checkbox的全选反选及自动判断是否全选状态

    动态生成的Gridview的前台html代码如下:     <table class="usertableborder" cellspacing="0" ...

  3. ExtJs动态生成treepanel的Json格式

    在节点中加上"checked"属性,会自动生成checkbox. 获取选中节点 var nodeArray = ""; var nodesObj = mytre ...

  4. 关于动态生成data组件

    /*! * WeX5 v3 (http://www.justep.com) * Copyright 2015 Justep, Inc. * Licensed under Apache License, ...

  5. Jquery 动态生成表单 并将表单数据 批量通过Ajax插入到数据库

    利用Jquery 动态生成 Table 表单 之后利用each 方法来遍历所有文本框获取文本的value值  并通过Ajax 将数据 提交到Web服务里把数据插入数据库 Html页面 <!DOC ...

  6. 为什么JS动态生成的input标签在后台有时候没法获取到

    最近在做一个产品添加的功能,需求有点奇葩,所以在添加的时候免不了要用到动态生成控件,然后我就使用了JS去动态生成一些 checkbox类型的input标签,在以前用asp.net在后台生成的input ...

  7. bootstrap动态生成层级ul-li 新闻预览 常用方法

    <div class="row" id="add-withinfosortId-row" style="display: none"& ...

  8. ASP.NET动态生成GridView的使用

    根据DataTable动态生成包含checkbox的GridView,其中DataTable中对应checkbox那一列的值必须为bool值. public static GridView Dynam ...

  9. AngularJS中获取ng-repeat动态生成的ng-model值

    需求:通过ng-repeat动态生成的CheckBox,实现勾选控制对应的批次号.如图: html: <div class="clearfix"> <div cl ...

随机推荐

  1. [原]通过配合ffmpeg.exe获取视频文件时长

    import subprocess import os import time def getTime(flvpath,fid): #file_str = '1.flv' file_str = flv ...

  2. spring mvc 第一天【注解实现springmvc的基本配置】

    创建pojo,添加标识类的注解@Controller,亦可添加该Handler的命名空间:设置类的@RequestMapping(value="/hr") 该类中的方法(Handl ...

  3. SECD machine简介

    secd machine是一种比较基础的虚拟机设计.一般是作为函数式语言的底层虚拟机. secd machine的"secd"四个字母分别指的是这种虚拟机的核心Stack, Env ...

  4. 抢凳子日数据sql

    --先找到档期select * from hv_item_info a where a.report_begdate > '2016-07-28' and a.report_begdate &l ...

  5. Java NIO教程 目录

    "Java NIO系列教程" 是笔者hans为NIO的初学者编写的一份入门教程,想仔细学习的同学可以按照顺序去阅读.由于我学的也不是特别的精,所以错误.疏漏在所难免,希望同学们指正 ...

  6. Ptex源码学习笔记-1

    Ptex是Walt Disney Animation Studios开发的纹理映射工具.在看一个叫appleseed的渲染器时看到他支持这种纹理,所以就查看一下,发现比较轻量,所以就想趁此机会学习下. ...

  7. Unity协程截图,WWWForm、WWW配合上传

    先说一下原理.. 截图有两种方法,第一种: Application.CaptureScreenshot(url); 这个API可以截全屏并保存到指定路径 这里我们不采用此方法 下面的代码采用第二种方法 ...

  8. 一个的unity学习系列的博客

    1.http://my.csdn.net/caoboya 2.http://my.csdn.net/OnafioO

  9. Android 7.0 UICC 分析(四)

    本文讲解SIMRecords /frameworks/opt/telephony/src/java/com/android/internal/telephony/uicc/SIMRecords.jav ...

  10. ios 关于状态栏的一些小知识

    一.改变状态栏颜色 状态栏分为两种颜色,默认的是黑色,这里想要改为白色: 分为两步: 第一步:在项目中找到plist文件,添加View controller-based status bar appe ...