在开发过程中,往往需要利用数据动态生成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. 图解直方图均衡化及其Python实现

    在理解直方图均衡化的过程中,参考了一些书籍和博客,让人困惑的是,笔者对于直方图的理解还是停留在表面,并没有深入理解其内涵.因此,本文拟结合图片对直方图的概念进行阐述,并给出其Python实现,最后对她 ...

  2. REMOVE ONCLICK DELAY ON WEBKIT FOR IPHONE

    Developing on the webkit for iPhone I encountered a curious delay ononClick events. It seems that th ...

  3. xshell xftp

    xshell : http://www.netsarang.com/xshell_download.html xftp:http://www.netsarang.com/products/xfp_ov ...

  4. webView 点击页面跳转到浏览器

    @interface ForumDetailViewController ()<UIWebViewDelegate> { NSUInteger _clickedNumber; } @end ...

  5. 关于apache httpd.conf脚本的理解

    新人一枚,这两天一直在研究lamp的搭建,感觉自己对apache理解的不够深彻,决定写这一篇(翻译)httpd.conf文件 未完待续 cat /usr/local/apache/conf/httpd ...

  6. java解析中国行政区域并在页面显示实现动态逐级筛选

    一.实现目标 首先会有一个存放中国行政区域数据的一个txt文件,用java读取并解析出来,并在页面上通过下拉框的形式展示出来.实现效果如下图,当选择完省份后,在选择该省份下的城市,然后在选择该城市下的 ...

  7. Activity之间传递参数(三)

    ------siwuxie095 传递值对象,即自定义的有数据类型的对象 1.首先 new 一个 class:User,用于创建自定义对象,同时右键 Generate 出 Constructor.se ...

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

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

  9. WebService基本概念及原理

    一.Web Service基本概念 WebService是一种跨编程语言和跨操作系统平台的远程调用技术.Web Service也叫XML Web Service WebService是一种可以接收从I ...

  10. ASP.NET    实现301状态重定向 实现搜索引擎友好

    4.0提供301转向 RedirectPermanent 使用该函数转向http状态码为301 备注     RedirectPermanent(String) 方法重载提供了一个 301 的 HTT ...