热门标签 | HotTags
当前位置:  开发笔记 > 前端 > 正文

ext代码生成器_YUI.Ext相关

见我的上一篇文章,XCodeBuilder不仅能生成.Net三层代码,还生成处理层代码和Ext脚本,以下是一个grid的示例。
本文件为:ext_editgrid_products.js,用来显示,编辑,删除products表的数据。

代码如下:


var productsgrid;
var productsstore;
var productslimit = 25; //每页显示条数
var productsListPostUrl = "/management/procrequest/Proc_products.ashx?action=getlist";
var productsModifyPostUrl = "/management/procrequest/Proc_products.ashx?action=modify";
var productsDeletePostUrl = "/management/procrequest/Proc_products.ashx?action=del";
function initproductsGrid(containerid) {
Ext.menu.RangeMenu.prototype.icOns= {
gt: 'images/greater_then.png',
lt: 'images/less_then.png',
eq: 'images/equals.png'
};
Ext.grid.filter.StringFilter.prototype.icon = 'images/find.png';
Ext.QuickTips.init();
function formatDate(value) {
return value ? value.dateFormat('M d, Y') : '';
};
var fm = Ext.form;
var sm = new Ext.grid.CheckboxSelectionModel();
var cm = new Ext.grid.ColumnModel([
sm,
{
id:'productId',
header: '产品编号',
dataIndex: 'productId',
sortable: true,
width:70,
editor: new fm.NumberField({
allowBlank: false,
allowNegative: false
})
},
{
header: '产品名称',
dataIndex: 'productName',
sortable: true,
width:120,
editor: new fm.TextField({
allowBlank: false,
allowNegative: false
})
},
{
header: '金额',
dataIndex: 'money',
sortable: true,
width:120,
editor: new fm.NumberField({
allowBlank: false,
allowNegative: false
})
},
{
header: '地址',
dataIndex: 'address',
sortable: true,
width:120,
editor: new fm.TextField({
allowBlank: false,
allowNegative: false
})
},
{
header: '电话',
dataIndex: 'tel',
sortable: true,
width:120,
editor: new fm.TextField({
allowBlank: false,
allowNegative: false
})
},
{
header: '备注',
dataIndex: 'remark',
sortable: false,
width:550,
editor: new fm.myHtmlEditor({
allowBlank: false,
allowNegative: false
})
},
{
header: '端口',
dataIndex: 'port',
sortable: true,
width:70,
editor: new fm.NumberField({
allowBlank: false,
allowNegative: false
})
}
]);
cm.defaultSortable = true;
/*
var Plant = Ext.data.Record.create([
]);
*/
productsstore = new Ext.data.JsonStore({
root: 'list',
totalProperty: 'totalCount',
idProperty: 'productId',
remoteSort: true,
fields: [
{name: 'productId' },{name: 'productName' },{name: 'money' },{name: 'address' },{name: 'tel' },{name: 'remark' },{name: 'port' }
],
proxy: new Ext.data.ScriptTagProxy({
url: productsListPostUrl
})
});
productsstore.setDefaultSort('productId', 'desc');
var filters = new Ext.grid.GridFilters({
filters: [
{ type: 'string', dataIndex: 'productId' }, { type: 'string', dataIndex: 'productName' }, { type: 'string', dataIndex: 'money' }, { type: 'string', dataIndex: 'address' }, { type: 'string', dataIndex: 'tel' }, { type: 'string', dataIndex: 'remark' }, { type: 'string', dataIndex: 'port' }
]
});
var pagingBar = new Ext.PagingToolbar({
pageSize: productslimit,
store: productsstore,
displayInfo: true,
displayMsg: '第 {0} - {1} 条记录,总共 {2} 条记录',
emptyMsg: "没有记录"
});
productsgrid = new Ext.grid.EditorGridPanel({
store: productsstore,
cm: cm,
sm: sm,
bodyStyle: 'width:100%',
autoWidth: true,
height: 620,
renderTo: containerid,
autoExpandColumn: 'productId',
frame: true,
clicksToEdit: 2,
plugins: [filters],
loadMask: true,
enableTabScroll: true,
tbar: [{
text: '添加',
tooltip: '添加新记录',
iconCls: 'add',
handler:function(){
openTab("addproducts", "添加products", null, initAddproductsForm);
}
},
'-', {
text: '编辑',
tooltip: '编辑选中记录',
iconCls: 'option',
handler: function() {
var selectedRow = productsgrid.getSelectionModel().getSelections();
if (selectedRow) {
var obj = selectedRow[0];
if (!obj)
return;
var id = obj.get("productId");
openTab("editproducts", "编辑products", null, initAddproductsForm, id, obj);
}
}
},
'-', {
text: '删除',
tooltip: '删除选中记录',
iconCls: 'remove',
handler: function() {
var selectedRow = productsgrid.getSelectionModel().getSelections();
Ext.MessageBox.confirm('Confirm', '你确定要删除你所选定的' + selectedRow.length + "项吗?", function(btn) {
if (btn == 'yes') {
if (selectedRow) {
for (var i = 0; i var obj = selectedRow[i];
var id = obj.get("productId");
productsstore.remove(obj);
$.ajax({
type: "POST",
url: productsDeletePostUrl,
dataType: "json",
data: "recordid=" + id,
success: function(msg) {
if (msg[0] && msg[0].string != "success")
productsstore.reload();
}
});
}
}
}
});
}
}],
bbar: pagingBar
});
productsstore.load({ params: { start: 0, limit: productslimit} });
productsgrid.on("afteredit", afterEdit, productsgrid);
function afterEdit(obj) {
var r = obj.record; //获取被修改的行
var fildname = obj.field; //获取被修改的列
var id = r.get("productId");
var fildval = obj.value;
$.ajax({
type: "POST",
url: productsModifyPostUrl,
dataType: "json",
data: { action: 'modify', fildname: fildname, id: id, fildval: fildval },
complete: function() {
},
success: function(msg) {
}
});
}
}


本文件为ext_add_products.js,用来添加或者编辑products表。

代码如下:


var productsAddPostUrl = "/management/procrequest/Proc_products.ashx?action=add";
var productsUpdatePostUrl = "/management/procrequest/Proc_products.ashx?action=update";
function initAddproductsForm(containerid, idstr, rowObj) {
if (!idstr)
idstr = containerid;
var productsForm = new Ext.FormPanel({
labelWidth: 100, // label settings here cascade unless overridden
url: productsAddPostUrl,
frame: true,
bodyStyle: 'padding:5px 5px 0',
autoWidth: true,
defaults: { width: '350' },
defaultType: 'textfield',
renderTo: containerid,
items: [
{
xtype: 'hidden',
name: 'productId',
id: 'productId' + idstr,
value: null == rowObj ? null : rowObj.get("productId"),
readOnly: true
}

, {
xtype: 'textfield',
fieldLabel: '商品名称',
height: 20,
name: 'productName',
allowBlank: false,
value: null == rowObj ? null : rowObj.get("productName"),
id: 'productName' + idstr
}
, {
xtype: 'numberfield',
fieldLabel: '价格',
height: 20,
name: 'money',
allowBlank: false,
value: null == rowObj ? null : rowObj.get("money"),
id: 'money' + idstr
}
, {
xtype: 'textfield',
fieldLabel: '地址',
height: 20,
name: 'address',
value: null == rowObj ? null : rowObj.get("address"),
id: 'address' + idstr
}
, {
xtype: 'textfield',
fieldLabel: '电话',
height: 20,
name: 'tel',
value: null == rowObj ? null : rowObj.get("tel"),
id: 'tel' + idstr
}
, {
xtype: 'myhtmleditor',
fieldLabel: '备注',
height: 400, width: 600,
name: 'remark',
value: null == rowObj ? null : rowObj.get("remark"),
id: 'remark' + idstr
}
, {
xtype: 'numberfield',
fieldLabel: '端口',
height: 20,
name: 'port',
value: null == rowObj ? null : rowObj.get("port"),
id: 'port' + idstr
}
],
buttons: [{
text: '保存',
handler: function() {
if (!productsForm.form.isValid())
return;
productsForm.form.submit({
meghod: 'post',
url: !isNaN(idstr) && parseInt(idstr) > 0 ? productsUpdatePostUrl : productsAddPostUrl,
waitMsg: '正在保存,请稍候...',
success: function() {
Ext.MessageBox.show({
title: '保存结果',
msg: '保存成功',
buttons: Ext.MessageBox.OK,
icon: Ext.MessageBox.INFO
});
},
failure: function() {
Ext.MessageBox.show({
title: '保存结果',
msg: '保存失败',
buttons: Ext.MessageBox.OK,
icon: Ext.MessageBox.ERROR
});
}

});

}
}]
});

}

推荐阅读
  • 本文介绍了前端人员必须知道的三个问题,即前端都做哪些事、前端都需要哪些技术,以及前端的发展阶段。初级阶段包括HTML、CSS、JavaScript和jQuery的基础知识。进阶阶段涵盖了面向对象编程、响应式设计、Ajax、HTML5等新兴技术。高级阶段包括架构基础、模块化开发、预编译和前沿规范等内容。此外,还介绍了一些后端服务,如Node.js。 ... [详细]
  • 本文介绍了如何使用jQuery和AJAX来实现动态更新两个div的方法。通过调用PHP文件并返回JSON字符串,可以将不同的文本分别插入到两个div中,从而实现页面的动态更新。 ... [详细]
  • 本文介绍了Java后台Jsonp处理方法及其应用场景。首先解释了Jsonp是一个非官方的协议,它允许在服务器端通过Script tags返回至客户端,并通过javascript callback的形式实现跨域访问。然后介绍了JSON系统开发方法,它是一种面向数据结构的分析和设计方法,以活动为中心,将一连串的活动顺序组合成一个完整的工作进程。接着给出了一个客户端示例代码,使用了jQuery的ajax方法请求一个Jsonp数据。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 本文介绍了使用AJAX的POST请求实现数据修改功能的方法。通过ajax-post技术,可以实现在输入某个id后,通过ajax技术调用post.jsp修改具有该id记录的姓名的值。文章还提到了AJAX的概念和作用,以及使用async参数和open()方法的注意事项。同时强调了不推荐使用async=false的情况,并解释了JavaScript等待服务器响应的机制。 ... [详细]
  • Java实战之电影在线观看系统的实现
    本文介绍了Java实战之电影在线观看系统的实现过程。首先对项目进行了简述,然后展示了系统的效果图。接着介绍了系统的核心代码,包括后台用户管理控制器、电影管理控制器和前台电影控制器。最后对项目的环境配置和使用的技术进行了说明,包括JSP、Spring、SpringMVC、MyBatis、html、css、JavaScript、JQuery、Ajax、layui和maven等。 ... [详细]
  • 使用在线工具jsonschema2pojo根据json生成java对象
    本文介绍了使用在线工具jsonschema2pojo根据json生成java对象的方法。通过该工具,用户只需将json字符串复制到输入框中,即可自动将其转换成java对象。该工具还能解析列表式的json数据,并将嵌套在内层的对象也解析出来。本文以请求github的api为例,展示了使用该工具的步骤和效果。 ... [详细]
  • 本文介绍了高校天文共享平台的开发过程中的思考和规划。该平台旨在为高校学生提供天象预报、科普知识、观测活动、图片分享等功能。文章分析了项目的技术栈选择、网站前端布局、业务流程、数据库结构等方面,并总结了项目存在的问题,如前后端未分离、代码混乱等。作者表示希望通过记录和规划,能够理清思路,进一步完善该平台。 ... [详细]
  • 使用正则表达式爬取36Kr网站首页新闻的操作步骤和代码示例
    本文介绍了使用正则表达式来爬取36Kr网站首页所有新闻的操作步骤和代码示例。通过访问网站、查找关键词、编写代码等步骤,可以获取到网站首页的新闻数据。代码示例使用Python编写,并使用正则表达式来提取所需的数据。详细的操作步骤和代码示例可以参考本文内容。 ... [详细]
  • 本文介绍了一种处理AJAX操作授权过期的全局方式,以解决Asp.net MVC中Session过期异常的问题。同时还介绍了基于WebImage的图片上传工具类。详细内容请参考链接:https://www.cnblogs.com/starluck/p/8284949.html ... [详细]
  • 在Android中解析Gson解析json数据是很方便快捷的,可以直接将json数据解析成java对象或者集合。使用Gson解析json成对象时,默认将json里对应字段的值解析到java对象里对应字段的属性里面。然而,当我们自己定义的java对象里的属性名与json里的字段名不一样时,我们可以使用@SerializedName注解来将对象里的属性跟json里字段对应值匹配起来。本文介绍了使用@SerializedName注解解析json数据的方法,并给出了具体的使用示例。 ... [详细]
  • 从零基础到精通的前台学习路线
    随着互联网的发展,前台开发工程师成为市场上非常抢手的人才。本文介绍了从零基础到精通前台开发的学习路线,包括学习HTML、CSS、JavaScript等基础知识和常用工具的使用。通过循序渐进的学习,可以掌握前台开发的基本技能,并有能力找到一份月薪8000以上的工作。 ... [详细]
  • express工程中的json调用方法
    本文介绍了在express工程中如何调用json数据,包括建立app.js文件、创建数据接口以及获取全部数据和typeid为1的数据的方法。 ... [详细]
  • 本文介绍了DataTables插件的官方网站以及其基本特点和使用方法,包括分页处理、数据过滤、数据排序、数据类型检测、列宽度自动适应、CSS定制样式、隐藏列等功能。同时还介绍了其易用性、可扩展性和灵活性,以及国际化和动态创建表格的功能。此外,还提供了参数初始化和延迟加载的示例代码。 ... [详细]
  • Vue基础一、什么是Vue1.1概念Vue(读音vjuː,类似于view)是一套用于构建用户界面的渐进式JavaScript框架,与其它大型框架不 ... [详细]
author-avatar
jackdaosen900
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有