课程表

Ext.js课程

工具箱
速查手册

Ext.js 表单

当前位置:免费教程 » JS/JS库/框架 » Ext.js

描述

形式:在大多数Web应用程序表单是最重要的小部件从用户获取信息,如登录表单/反馈表单,以便该值可以保存在数据库中,以供将来参考。窗体小部件用于此目的。
在创建表单之前,我们应该知道xtype。
xType定义Ext JS UI组件的类型,它在组件的渲染期间确定,例如元素可以是一个文本框,对于该文本框我们有xType作为textField,或者元素可以只有数值,我们有Numeric xType。

不同类型的xType:

文本域
此xType表示用户可以输入值的文本字段。 文本框的Ext JS类是“Ext.Form.Field.Text”

  1. {
  2. xtype: 'textfield',
  3. fieldLabel: 'Text field'
  4. }

文本区域
这是为了表示一个文本区域。 Ext JS类为“Ext.form.field.TextArea”

  1. {
  2. xtype: 'textarea',
  3. fieldLabel: 'Text Area'
  4. }

显示字段
这是为了表示一个显示文本字段。 Ext JS类为“Ext.form.Label”

  1. {
  2. xtype: 'displayfield',
  3. fieldLabel: 'Display Field''
  4. }

日期字段
这是为了表示一个日期字段,它具有日期选择器来选择日期。 Ext JS类为“Ext.form.field.Date”

  1. {
  2. xtype: 'datefield',
  3. fieldLabel: 'Date picker'
  4. }

按钮
这是一个按钮。 Ext JS类为“Ext.button.Button”

  1. {
  2. xtype: 'button',
  3. text : 'Button'
  4. }

无线电场
这是为了表示一个无线电字段,我们可以在所有单选按钮中选择任何一个,或者可以自定义一次选择多个。 Ext JS类为“Ext.form.field.Radio”。

  1. {
  2. xtype : 'fieldcontainer',
  3. fieldLabel : 'Radio field',
  4. defaultType: 'radiofield',
  5. defaults: {
  6. flex: 1
  7. },
  8. layout: 'hbox',
  9. items: [{
  10. boxLabel : 'A',
  11. inputValue: 'a',
  12. id : 'radio1'
  13. },{
  14. boxLabel : 'B',
  15. inputValue: 'b',
  16. id : 'radio2'
  17. },{
  18. boxLabel : 'C',
  19. inputValue: 'c',
  20. id : 'radio3'
  21. }]
  22. }

CHECKBOX字段
这是一个复选框字段,我们可以一次选择多个值。 Ext JS类为“Ext.form.field.Checkbox”

  1. {
  2. xtype: 'fieldcontainer',
  3. fieldLabel: 'Check Box Field',
  4. defaultType: 'checkboxfield',
  5. items: [{
  6. boxLabel : 'HTML',
  7. inputValue: 'html',
  8. id : 'checkbox1'
  9. },{
  10. boxLabel : 'CSS',
  11. inputValue: 'css',
  12. checked : true,
  13. id : 'checkbox2'
  14. },{
  15. boxLabel : 'JavaScript',
  16. inputValue: 'js',
  17. id : 'checkbox3'
  18. }]
  19. }

组合框
这是一个组合框。 组合框包含项目列表。 Ext JS类为“Ext.form.field.ComboBox”

  1. {
  2. xtype : 'combobox',
  3. fieldLabel: 'Combo box',
  4. store: store,
  5. valueField: 'name'
  6. }
  7. // store for drop down values
  8. var store = Ext.create('Ext.data.Store', {
  9. id : 'statesid',
  10. fields: ['abbr', 'name'],
  11. data : [
  12. {"abbr":"HTML", "name":"HTML"},
  13. {"abbr":"CSS", "name":"CSS"},
  14. {"abbr":"JS", "name":"JavaScript"}
  15. ]
  16. });

时间字段
这是为了表示一个时间字段,其中可以预定义最大和最小时间值。 Ext JS类为“Ext.form.field.Time”

  1. {
  2. xtype: 'timefield',
  3. fieldLabel: 'Time field',
  4. minValue: '6:00 AM',
  5. maxValue: '8:00 PM',
  6. increment: 30,
  7. anchor: '100%'
  8. }

文件
这是一个文件上传字段,我们可以浏览和上传文件。 Ext JS类为“Ext.form.field.File”

  1. {
  2. xtype: 'filefield',
  3. fieldLabel: 'File field',
  4. labelWidth: 50,
  5. msgTarget: 'side',
  6. allowBlank: false,
  7. anchor: '100%',
  8. buttonText: 'Select File...'
  9. }

螺旋桨
这是一个微调字段,其中列表可以旋转和添加。 Ext JS类为“Ext.form.field.Spinner”

  1. {
  2. xtype: 'spinnerfield',
  3. fieldLabel: 'Spinner field'
  4. }

NUMERIC FIELD
这是为了表示一个数字字段,其中我们可以预先定义max和min值。 Ext JS类为“Ext.form.field.Number”

  1. {
  2. xtype: 'numberfield',
  3. anchor: '100%',
  4. fieldLabel: 'Numeric field',
  5. maxValue: 99,
  6. minValue: 0
  7. }

隐藏字段
作为名称解释这个xtype是保持值隐藏。

  1. {
  2. xtype: 'hiddenfield',
  3. value: 'value from hidden field'
  4. }

形式面板的语法
下面是创建表单的简单语法

  1. Ext.create('Ext.form.Panel');

例子
下面是一个简单的例子,显示所有xtype的形式

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <link href="//cdn.bootcss.com/extjs/6.2.0/classic/theme-classic/resources/theme-classic-all.css" rel="stylesheet" />
  5. <script type="text/javascript" src="//cdn.bootcss.com/extjs/6.2.0/ext-all.js"></script>
  6. <script type="text/javascript">
  7. Ext.onReady(function() {
  8. Ext.create('Ext.form.Panel', {
  9. id: 'newForm',
  10. renderTo: 'formId',
  11. border: true,
  12. width: 600,
  13. items: [{
  14. xtype: 'textfield',
  15. fieldLabel: 'Text Field'
  16. },{
  17. xtype: 'displayfield',
  18. fieldLabel: 'Display Field'
  19. },{
  20. xtype: 'textarea',
  21. fieldLabel: 'Text Area'
  22. },{
  23. xtype: 'datefield',
  24. fieldLabel: 'Date picker'
  25. },{
  26. xtype: 'button',
  27. text: 'Button'
  28. },{
  29. xtype: 'fieldcontainer',
  30. fieldLabel: 'Radio field',
  31. defaultType: 'radiofield',
  32. defaults: {
  33. flex: 1
  34. },
  35. layout: 'hbox',
  36. items: [{
  37. boxLabel: 'A',
  38. inputValue: 'a',
  39. id: 'radio1'
  40. },{
  41. boxLabel: 'B',
  42. inputValue: 'b',
  43. id: 'radio2'
  44. },{
  45. boxLabel: 'C',
  46. inputValue: 'c',
  47. id: 'radio3'
  48. }]
  49. },{
  50. xtype: 'fieldcontainer',
  51. fieldLabel: 'Check Box Field',
  52. defaultType: 'checkboxfield',
  53. items: [{
  54. boxLabel: 'HTML',
  55. inputValue: 'html',
  56. id: 'checkbox1'
  57. },{
  58. boxLabel: 'CSS',
  59. inputValue: 'css',
  60. checked: true,
  61. id: 'checkbox2'
  62. },{
  63. boxLabel: 'JavaScript',
  64. inputValue: 'js',
  65. id: 'checkbox3'
  66. }]
  67. },{
  68. xtype: 'hiddenfield',
  69. name: 'hidden field ',
  70. value: 'value from hidden field'
  71. },{
  72. xtype: 'numberfield',
  73. anchor: '100%',
  74. fieldLabel: 'Numeric Field',
  75. maxValue: 99,
  76. minValue: 0
  77. },{
  78. xtype: 'spinnerfield',
  79. fieldLabel: 'Spinner Field',
  80. step: 6,
  81. // override onSpinUp (using step isn't neccessary)
  82. onSpinUp: function() {
  83. var me = this;
  84. if (!me.readOnly) {
  85. var val = me.step; // set the default value to the step value
  86. if(me.getValue() !== '') {
  87. val = parseInt(me.getValue().slice(0, -5)); // gets rid of " Pack"
  88. }
  89. me.setValue((val + me.step) + ' Pack');
  90. }
  91. },
  92.  
  93. // override onSpinDown
  94. onSpinDown: function() {
  95. var me = this;
  96. if (!me.readOnly) {
  97. if(me.getValue() !== '') {
  98. val = parseInt(me.getValue().slice(0, -5)); // gets rid of " Pack"
  99. }
  100. me.setValue((val - me.step) + ' Pack');
  101. }
  102. }
  103. },{
  104. xtype: 'timefield',
  105. fieldLabel: 'Time field',
  106. minValue: '6:00 AM',
  107. maxValue: '8:00 PM',
  108. increment: 30,
  109. anchor: '100%'
  110. },{
  111. xtype: 'combobox',
  112. fieldLabel: 'Combo Box',
  113. store: Ext.create('Ext.data.Store', {
  114. fields: ['abbr', 'name'],
  115. data: [{
  116. 'abbr': 'HTML',
  117. 'name': 'HTML'
  118. },{
  119. 'abbr': 'CSS',
  120. 'name': 'CSS'
  121. },{
  122. 'abbr': 'JS',
  123. 'name': 'JavaScript'
  124. }]
  125. }),
  126. valueField: 'abbr',
  127. displayField: 'name'
  128. },{
  129. xtype: 'filefield',
  130. fieldLabel: 'File field',
  131. labelWidth: 50,
  132. msgTarget: 'side',
  133. allowBlank: false,
  134. anchor: '100%',
  135. buttonText: 'Select File...'
  136. }]
  137. });
  138. });
  139. </script>
  140. </head>
  141. <body>
  142. <div id = "formId"></div>
  143. </body>
  144. </html>

尝试一下

转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号