ExtJs 3.0 动态生成 CheckBox
在开发过程中,往往需要利用数据动态生成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的更多相关文章
- 动态生成CheckBox(Winform程序)
在做用户权限设置功能时,需要做一个动态生成权限列表的功能.(笔记.分享) //1.清空权限控件组的默认控件 panelPermissions.Controls.Clear(); _groupBoxLi ...
- jquery控制动态生成的gridview中多列checkbox的全选反选及自动判断是否全选状态
动态生成的Gridview的前台html代码如下: <table class="usertableborder" cellspacing="0" ...
- ExtJs动态生成treepanel的Json格式
在节点中加上"checked"属性,会自动生成checkbox. 获取选中节点 var nodeArray = ""; var nodesObj = mytre ...
- 关于动态生成data组件
/*! * WeX5 v3 (http://www.justep.com) * Copyright 2015 Justep, Inc. * Licensed under Apache License, ...
- Jquery 动态生成表单 并将表单数据 批量通过Ajax插入到数据库
利用Jquery 动态生成 Table 表单 之后利用each 方法来遍历所有文本框获取文本的value值 并通过Ajax 将数据 提交到Web服务里把数据插入数据库 Html页面 <!DOC ...
- 为什么JS动态生成的input标签在后台有时候没法获取到
最近在做一个产品添加的功能,需求有点奇葩,所以在添加的时候免不了要用到动态生成控件,然后我就使用了JS去动态生成一些 checkbox类型的input标签,在以前用asp.net在后台生成的input ...
- bootstrap动态生成层级ul-li 新闻预览 常用方法
<div class="row" id="add-withinfosortId-row" style="display: none"& ...
- ASP.NET动态生成GridView的使用
根据DataTable动态生成包含checkbox的GridView,其中DataTable中对应checkbox那一列的值必须为bool值. public static GridView Dynam ...
- AngularJS中获取ng-repeat动态生成的ng-model值
需求:通过ng-repeat动态生成的CheckBox,实现勾选控制对应的批次号.如图: html: <div class="clearfix"> <div cl ...
随机推荐
- mongodb的linux环境搭建
一.启动 [mongodb@node1 ~]$ mongod -f /data/config/shard1.confmongod: /usr/lib64/libcrypto.so.10: no ver ...
- StringUtils方法全集
org.apache.commons.lang.StringUtils中方法的操作对象是java.lang.String类型的对象,是JDK提供的String类型操作方法的补充,并且是null安全的( ...
- Versioned table in Netezza
Problem One QC process need to obtain tables and their row counts in a database in Netezza. We use t ...
- 集合框架遍历方式之——for-each循环
从Java5起,在Java中有了for-each循环,可以用来循环遍历collection和array.Foreach循环允许你在无需保持传统for循环中的索引,或在使用iterator /ListI ...
- leveldb 学习笔记之VarInt
在leveldb在查找比较时的key里面保存key长度用的是VarInt,何为VarInt呢,就是变长的整数,每7bit代表一个数,第8bit代表是否还有下一个字节, 1. 比如小于128(一个字节以 ...
- [转]Oracle 经验集
-- 转换字符串为日期格式 to_date('2011-12-30 11:54:30','yyyy-MM-dd:hh24:mi:ss') Oracel 用 C# 连接,Microsoft 自带的 Sy ...
- TFS 服务端默认端口更改
由于服务商限制8080,为了外网能访问.如果可以做映射还好.如果不能那就修改默认端口 以下为网上资源 安装完Team Foundation Server 2005 后,默认的端口是8080.如果想要事 ...
- 1、C语言基本数据类型
1.分类如图: 2.大小如下 char 1字节 short 2字节 int ...
- 在c#中IO流读写操作
1.使用FileStream读写文件 文件头: using System;using System.Collections.Generic;using System.Text;using System ...
- SQL 存储过程优化经验
经现场同事反映,他们用的好好的XML 导出工具最近一直报错,经常报数据库连接超时,查看数据库发现已经有100G 以上有空间了. 但导出数据的存储过程里面每次按时间只导1000多条数据,近理说有时间过滤 ...