- 注册时间
- 2013-4-19
- 最后登录
- 2024-7-1
- 阅读权限
- 200
- 积分
- 6311
- 精华
- 0
- 帖子
- 637
![Rank: 80](static/image/common/star_level3.gif) ![Rank: 80](static/image/common/star_level3.gif) ![Rank: 80](static/image/common/star_level3.gif) ![Rank: 80](static/image/common/star_level3.gif) ![Rank: 80](static/image/common/star_level3.gif)
|
mysql创建表article_type
=======数据库=======
CREATE TABLE `article_type` (
`_id` int(11) NOT NULL auto_increment,
`_name` text,
PRIMARY KEY (`_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of article_type
-- ----------------------------
INSERT INTO article_type VALUES ('1', '生活');
INSERT INTO article_type VALUES ('2', '科技');
=======CI============
model: article_type.php
<?php
class article_type extends CI_Model{
function article_type(){
parent::__construct();
}
function getAllArticleType(){
$this->db->select('_id,_name');
$query = $this->db->get('article_type');
$data=array();
$rearr=array();
if($query->num_rows()>0){
foreach($query->result() as $row){
$data['id']=$row->_id;
$data['name']=$row->_name;
array_push($rearr,$data);
}
}
return $rearr;
}
}
?>
controller:article.php
<?php
class article extends CI_Controller{
function article(){
parent::__construct();
$this->load->helper("url");
}
function data_article_type() {
$this->load->model('article_type');
$data = $this->article_type->getAllArticleType();
echo json_encode($data);
}
}
?>
到这步 访问 http://10.6.0.117/index.php/article/data_article_type
能够得到ci框架返回的json字符串: [{"id":"1","name":"\u751f\u6d3b"},{"id":"2","name":"\u79d1\u6280"}]
========EXTJS==============
<script type="text/javascript">
Ext.onReady(function(){
Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['id', 'name']
});
var mstore = Ext.create('Ext.data.Store', {
model: 'User',
proxy: {
type: 'ajax',
url : 'http://10.6.0.117/index.php/article/data_article_type',
reader: {
type: 'json'
}
}
});
mstore.load();
Ext.create('Ext.grid.Panel', {
store: mstore,
columns: [
{ text: 'id', dataIndex: 'id' },
{ text: 'name', dataIndex: 'name'}
],
height: 200,
renderTo: Ext.getBody()
});
});
</script>
到此,读取数据库显示基本ok了,接下来做写入数据库的工作
==========这个是treestore和数据库关联================
[{text:'aaaa',leaf:true,iconCls:'settings'},{text:'bbbb',leaf:true,iconCls:'settings'}]
var treestore = Ext.create('Ext.data.TreeStore', {
defaultRootText:"全部分类",
root: {
expanded: true
},
proxy: {
type: 'ajax',
url: 'http://10.6.0.117/index.php/article/test_tree_loader'
}
});
this.typeView = Ext.create('Ext.tree.TreePanel', {
id: "typeList",
title: '文章分类',
store: treestore,
useArrows: true,
tools: [{type: 'plus',handler: this.onAddClick}],
rootVisible: true
});
===============================
|
|