刚学ext遇到问题

zhangyelove1314 2012-10-30 07:57:27
我看到一个例子 然后照着 仿写了一个grid Ext.grid.Panel 用Ext.grid.plugin.RowEditing这个东西添加数据 这个东西保存store = Ext.create('Ext.data.Store', 当然 代理部分没有弄明白 我就写了 data:[] 一切都解决了 可以传到后台
可是我忽然发现 我的 grid里面 不仅仅是需要文本框输入数据 还需要下拉菜单 其中一部分下拉菜单是死的数据 另一部分是从后台传过来的 我应该怎么改 下面是我JS代码
...全文
133 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangyelove1314 2012-10-30
  • 打赏
  • 举报
回复
listeners: {
write还有代理下面 这个我也不知道是什么意思 如果有大神的话 希望告诉我一下
zhangyelove1314 2012-10-30
  • 打赏
  • 举报
回复
//意思就是这个页面需要用到哪些组件,然后就预先加载,多余不用加载的组件就不管他了.提高运行速度
//require 需要, 要求, 命令


/*定义一个Person类 继承 Ext.data.Model
并设置如下字段
{ name: 'id',type: 'int',useNull: true}
email
first
last
*/
/*(Fields)属性,这个属性接受一个数组。用来设置Model中所包含的字段*/
Ext.define('Person', {
extend: 'Ext.data.Model',
fields: [{
name: 'id',
type: 'int',
useNull: true
}, 'email', 'first', 'last'],
//验证字段,以下为
/* 哈哈的最小长度是1
嘿嘿的最小长度是1
熊猫的最小长度是1*/
validations: [{
type: 'length',
field: '张野',
min: 1
}, {
type: 'length',
field: '赵晶',
min: 1
}, {
type: 'length',
field: '小兔崽',
min: 1
}]
});
var grid;
var store;
//说明:onReady内的语句块会在页面上下文加载后再执行
Ext.onReady(function(){
//定义一个变量store
store = Ext.create('Ext.data.Store', {
autoLoad: true,//是否自动加载
autoSync: true,//是否自动同步
model: 'Person',//解析数据的模型,模型可以代替proxy和fields配置
/* proxy: {//数据代理(其实就是发送ajax来请求数据用的)
type: 'rest',//使用rest请求
url: 'app.php/users',//url路径
// 读取数据的工具(数据代理)
reader: {
// 读取方式按照json字符串格式读取
type: 'json',
// json解析成js对象之后读取所有数据(通常是数组)的属性名称。
root: 'data'
},

writer: {
type: 'json'
}
}*/
data:[]
,
listeners: {
write: function(store, operation){
alert("listeners");
var record = operation.getRecords()[0],
name = Ext.String.capitalize(operation.action),
verb;


if (name == 'Destroy') {
record = operation.records[0];
verb = 'Destroyed';
} else {
verb = name + 'd';
}
Ext.example.msg(name, Ext.String.format("{0} user: {1}", verb, record.getId()));

}
}
});

var rowEditing = Ext.create('Ext.grid.plugin.RowEditing');

grid = Ext.create('Ext.grid.Panel', {
renderTo: 'req',
plugins: [rowEditing],

height: 300,
frame: true,
title: '请求报文',
store: store,
iconCls: 'icon-user',
columns: [ {
text: '哈哈',
flex: 1,
sortable: true,
dataIndex: 'email',
field: {
xtype: 'textfield'
}
}, {
header: '缺臭臭',
width: 80,
sortable: true,
dataIndex: 'first',
field: {
xtype: 'textfield'
}
}, {
xtype: 'timefield',
text: '熊猫',
width: 80,
sortable: true,
dataIndex: 'last',
field: {
xtype: 'textfield'
}
}],
dockedItems: [{
xtype: 'toolbar',
items: [{
text: '添加',
iconCls: 'icon-add',
handler: function(){
// empty record
store.insert(0, new Person());
rowEditing.startEdit(0, 0);
}
}, '-', {
itemId: 'delete',
text: '删除',
iconCls: 'icon-delete',
disabled: true,
handler: function(){
var selection = grid.getView().getSelectionModel().getSelection()[0];
if (selection) {
store.remove(selection);
}
}
}]
}]
});
grid.getSelectionModel().on('selectionchange', function(selModel, selections){
grid.down('#delete').setDisabled(selections.length === 0);
});

});

87,921

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧