Sha*_*din 2 grid search extjs store extjs4.1
我有表格和网格.用户必须在表单字段中输入数据,然后在网格中显示相关记录.
我想实现一个搜索表单,例如:用户将键入学生的姓名和性别,然后将获得所有学生的网格具有相同的名称和性别.
因此,我使用Ajax将表单字段值发送到PHP,然后创建一个json_encode将在网格存储中使用的值.
我真的不确定我的想法是否合适.但我还没有找到另一种方法.
问题是我的商店有一个错误,但我无法弄清楚它是什么.我收到此错误:
Uncaught TypeError: Cannot read property 'buffered' of undefined
我的看法:
{
xtype: 'panel',
layout: "fit",
id: 'searchResult',
flex: 7,
title: '<div style="text-align:center;"/>SearchResultGrid</div>',
items: [{
xtype: 'gridpanel',
store: 'advSearchStore',
id: 'AdvSearch-grid',
columns: [{
xtype: 'gridcolumn',
dataIndex: 'name',
align: 'right',
text: 'name'
}, {
xtype: 'gridcolumn',
dataIndex: 'gender',
align: 'right',
text: 'gender'
}
],
viewConfig: {
id: 'Arr',
emptyText: 'noResult'
},
requires: ['MyApp.PrintSave_toolbar'],
dockedItems: [{
xtype: 'PrintSave_tb',
dock: 'bottom',
}]
}]
}
Run Code Online (Sandbox Code Playgroud)
我的控制器:
.
.
.
xmlhttp.open("GET","AdvSearch.php?search_name="+search_name,true);
xmlhttp.send(null);
Run Code Online (Sandbox Code Playgroud)
我的PHP脚本:
if (!$con) {
throw new Exception("Error in connection to DB");
}
$query ="SELECT name, gender FROM students WHERE name ILIKE '%$search_name%' ";
$result = pg_query($query);
while ($row = pg_fetch_array($result)) {
$Arr[] = array('name' => $row[0], 'gender' => $row[1]);
}
$searchResult_list = array();
$searchResult_list['success'] = true;
$searchResult_list['Arr'] = $Arr;
$searchResult_list['totalCount'] = count( $searchResult_list['Arr'] );
echo json_encode($searchResult_list);
if (!$result)
die("Error in query: " . pg_last_error());
pg_close($con);
Run Code Online (Sandbox Code Playgroud)
我的商店,型号:
Ext.define('AdvSearchPost', {
extend: 'Ext.data.Model',
proxy: {
type: 'ajax',
url: 'AdvSearch.php',
reader: {
type: 'json',
root: 'Arr',
totalProperty: 'totalCount'
}
},
fields: [{
name: 'name'
}, {
name: 'type_and_cargo'
}
]
});
advSearchStore = Ext.create('Ext.data.Store', {
pageSize: 10,
model: 'AdvSearchPost'
});
Run Code Online (Sandbox Code Playgroud)
那么这只是你商店名称的错字.
该错误Uncaught TypeError: Cannot read property 'buffered' of undefined仅表示商店无法绑定.这可能有点误导.
尝试使用网格
store: advSearchPost
Run Code Online (Sandbox Code Playgroud)
要么
store: Ext.StoreMgr.lookup('AdvSearchPost') // if in any form a controller takes care about your store
Run Code Online (Sandbox Code Playgroud)
它会起作用.
编辑
我猜你没有任何控制器所以我建议你像这样创建你的商店
Ext.create('Ext.data.Store', {
pageSize: 10,
model: 'AdvSearchPost',
storeId: 'AdvSearchPost'
});
Run Code Online (Sandbox Code Playgroud)
这将使您能够StoreManager从任何地方(创建后)接收商店.这也将使最后一个语句在没有任何控制器的情况下工作.
| 归档时间: |
|
| 查看次数: |
18264 次 |
| 最近记录: |