Ext4.1动态生成checkboxgroup对象
Ext4.1动态生成checkboxgroup对象的原理很简单,用ext的ajax类库发送ajax请求动态页获得items对象的字符串内容,eval生成json对象,然后再生成checkboxgroup对象,配置checkboxgroup的items对象为返回的json字符串内容即可【注意要eval生成json对象,不能直接是字符串】。
数据源data.txt内容
[{"boxLabel":"Item1","name":"name","checked":true,"inputValue":1}
,{"boxLabel":"Item2","name":"name","checked":true,"inputValue":2}
,{"boxLabel":"Item3","name":"name","inputValue":3}
,{"boxLabel":"Item4","name":"name","inputValue":4}]
示例代码如下
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Ajax动态生成Checkbox Groups对象</title> <link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" /> <script type="text/javascript" src="../../ext-all.js"></script> <link rel="stylesheet" type="text/css" href="../shared/example.css" /> <script type="text/javascript"> Ext.onReady(function(){ Ext.Ajax.request({ url:'data.txt' ,//这里改成动态页,负责生成和data.txt一样的json字符串内容 success: function(resp,opts) { var items= eval('('+resp.responseText+')'); Ext.create('Ext.form.CheckboxGroup',{columns: 3,items:items,renderTo:document.body}); } , failure: function(resp,opts){alert('ERROR'+resp.status+'\n'+resp.responseText)} }); }); </script> </head> <body> <h1>Ajax动态生成Checkbox Groups对象</h1> </body> </html>
加支付宝好友偷能量挖...
原创文章,转载请注明出处:Ext4.1动态生成checkboxgroup对象