VS Code 使用代码片段
用VS code的代码片段功能,可以非常方便的插入一些固定的代码。为方便使用jQuery和easyui,自定义了下面的片段。
{
"My Ajax": {
"prefix": "ajax",
"body": [
"$.ajax({",
"\turl: '$1',",
"\ttype: 'post',",
"\tcache: false,",
"\tdata: {",
"\t\t$2",
"\t},",
"\tbeforeSend: function(){",
"\t\t$.messager.progress({ title: '请稍后', text: '正在提交...'});",
"\t},",
"\tsuccess: function(dat){",
"\t\t$.messager.progress('close');",
"\t\tif(dat && dat==='success'){",
"\t\t\t$3",
"\t\t}",
"\t\telse {",
"\t\t\t$.messager.alert('错误', dat ? dat : '未知错误', 'error');",
"\t\t}",
"\t},",
"\terror: function(){",
"\t\t$.messager.progress('close');",
"\t\t$.messager.alert('错误', '服务器异常', 'error');",
"\t}",
"});"
],
"description": "My ajax submit"
},
"Form Submit": {
"prefix": "submit",
"body": [
"$('$1').form('submit',{",
"\turl: '$2',",
"\tonSubmit: function(){",
"\t\tif( $(this).form('validate')) {",
"\t\t\t$.messager.progress({title: '请稍后', text: '正在提交...'});",
"\t\t\treturn true;",
"\t\t}",
"\t\telse",
"\t\t\treturn false;",
"\t},",
"\tsuccess: function(dat) {",
"\t\t$.messager.progress('close');",
"\t\tif(dat && dat==='success'){",
"\t\t\t$3",
"\t\t}",
"\t\telse {",
"\t\t\t$.messager.alert('错误', dat ? dat : '未知错误', 'error');",
"\t\t}",
"\t}",
"});"
],
"description": "My Form Submit"
},
"DataGrid" : {
"prefix": "datagrid",
"body": [
"var $1 = $('$2').datagrid({",
"\turl: '$3',",
"\tmethod: 'post',",
"\tsingleSelect: true,",
"\tstriped: true,",
"\tborder: false,",
"\tfit: true,",
"\trownumbers: false,",
"\tfitColumns: true,",
"\tpagination: true,",
"\tpageNumber: 1,",
"\tpageSize: 30,",
"\tpageList: [30, 50, 100, 200, 500, 1000],",
"\ttoolbar: '$4',",
"\tidField: '$5',",
"\tcolumns: [[",
"\t\t{title: '', field: '', width: 80, align: 'center', halign: 'center'},",
"\t\t{title: '', field: '', width: 80, align: 'center', halign: 'center'},",
"\t]],",
"\tonLoadSuccess: function ( data ) {",
"\t\tif ( data.total == 0 ) {",
"\t\t\t$.messager.show({title: '提示', msg: '查无记录'});",
"\t\t}",
"\t},",
"\tonLoadError: function(data) {",
"\t\tvar _this = $(this);",
"\t\t$.messager.alert('出现错误', data.responseText, 'error', function(){",
"\t\t\t_this.datagrid('loadData', {total: 1, rows: []});",
"\t\t});",
"\t}",
"});"
],
"description": "Data grid"
},
"Combobox" : {
"prefix": "combobox",
"body": [
"var $1 = $('$2').combobox({",
"\turl: '$3',",
"\twidth: 160,",
"\tprompt: '',",
"\trequired: false,",
"\teditable: false,",
"\tvalueField: 'value',",
"\ttextField: 'text',",
"\tdata:[$4],",
"\tvalue: '$5',",
"\tonSelect: function(r){",
"\t\t$6",
"\t}",
"});",
],
"description": "Combobox"
},
"TextBox" : {
"prefix": "textbox",
"body": [
"$('$1').textbox({",
"\twidth: 160$2,",
"\tprompt: '$3',",
"\trequired: false$4,",
"\tvalidType: '$5'",
"});"
],
"description": "Text Box"
},
"LinkButton": {
"prefix": "linkbutton",
"body":[
"$('$1').linkbutton({",
"\ttext: '$2',",
"\ticonCls: '$3',",
"\tplain: true$4,",
"\tonClick: function(){",
"\t\t$6",
"\t}",
"}).tooltip({ content: '$7' });"
],
"description": "Link Button"
},
"Link A": {
"prefix": "a",
"body" : "<a id=\"$1\" href=\"javascript:void(0)\"></a>",
"description": "Link A"
},
"Split Button": {
"prefix": "splitbutton",
"body": [
"$('$1').splitbutton({",
"\ttext: '$2',",
"\ticonCls: '$3',",
"\tplain: true$4,",
"\tmenu: '$5',",
"\tonClick: function(){",
"\t\t$6",
"\t}",
"});"
],
"description": "Split Button"
},
"Dialog" : {
"prefix": "dialog",
"body": [
"var $1 = $('$2').dialog({",
"\ttitle: '$3',",
"\ticonCls: '$4',",
"\twidth: 400$5,",
"\theight: 400$6,",
"\tmodal: true$7,",
"\tclosed: true,",
"\tbuttons:[{",
"\t\twidth: 100,",
"\t\ttext: '$8',",
"\t\ticonCls: '$9',",
"\t\thandler: function(){",
"\t\t\t",
"\t\t}",
"\t},{",
"\t\twidth: 100,",
"\t\ttext: '$10',",
"\t\ticonCls: '$11',",
"\t\thandler: function(){",
"\t\t\t$1.dialog('close')",
"\t\t}",
"\t}],",
"\tonBeforeOpen: function(){",
"\t\t",
"\t},",
"\tonClose: function(){",
"\t\t",
"\t}",
"});"
],
"description": "Dialog"
}
}