關於extjsmvc傳輸數據的信息

本文目錄一覽:

Extjs mvc 模式下怎麼獲得後台傳過來的數據。請寫詳細了謝謝了

extjs是一個前台的組件化的框架,在使用extjs組件時比如datagrid,會有一個url的配置參數,運行時自動請求你這個url,只要你後台傳遞過來的數據正確會自動顯示出來

extjs+mvc給Ext表單添加數據,然後以實體的形式返回到後台

js代碼:

Ext.define(‘app.site.projectWindow’, {

extend: ‘Ext.window.Window’,

border: 0,

height:380,

width: 440,

layout: {

type: ‘border’

},

title: ‘新建監測項目’,

constrain: true,

modal: true,

initComponent: function() {

var me = this;

var row = me.row;

var required = ‘span style=”color:red;font-weight:bold” data-qtip=”Required”*/span’;

Ext.applyIf(me, {

items: [

{

xtype: ‘form’,

region: ‘center’,

frame: true,

layout: {

type: ‘column’

},

defaults: {

margin:’2 0 0 0′,

columnWidth:.9

},

bodyPadding: 10,

title: ”,

items: [

{

xtype: ‘hiddenfield’,

fieldLabel: ‘監測因子id’,

name:’project.id’,

value:row==”?”:row.get(‘id’)

},

{

xtype: ‘textfield’,

fieldLabel: ‘名稱’,

name:’project.name’,

afterLabelTextTpl : required,

allowBlank : false,

value:row==”?”:row.get(‘name’)

},

{

xtype: ‘textfield’,

fieldLabel: ‘編碼’,

name:’project.code’,

value:row==”?”:row.get(‘code’)

},

{

xtype: ‘textfield’,

fieldLabel: ‘單位’,

afterLabelTextTpl : required,

allowBlank : false,

name:’project.unit’,

value:row==”?”:row.get(‘unit’)

},

{

xtype: ‘numberfield’,

fieldLabel: ‘最大值’,

afterLabelTextTpl : required,

allowBlank : false,

name:’project.maxNum’,

value:row==”?”:row.get(‘maxNum’)

},

{

xtype: ‘numberfield’,

fieldLabel: ‘最小值’,

afterLabelTextTpl : required,

allowBlank : false,

name:’project.minNum’,

value:row==”?”:row.get(‘minNum’)

},

{

xtype: ‘numberfield’,

fieldLabel: ‘報警值’,

afterLabelTextTpl : required,

allowBlank : false,

name:’project.alarmNum’,

value:row==”?”:row.get(‘alarmNum’)

},

{

xtype: ‘numberfield’,

fieldLabel: ‘小數位’,

name:’project.decimal’,

value:row==”?”:row.get(‘decimal’)

},

{

xtype: ‘textfield’,

fieldLabel: ‘國標No’,

name:’project.guobiaoNo’,//對象.屬性

value:row==”?”:row.get(‘guobiaoNo’)

},

{

xtype: ‘textfield’,

fieldLabel: ‘數據Mk’,

name:’project.shujuMk’,,//對象.屬性 value:row==”?”:row.get(‘shujuMk’)

},

{

xtype: ‘textareafield’,

fieldLabel: ‘備註’,

name:’project.mask’,

value:row==”?”:row.get(‘mask’)

}

]

}

],

buttonAlign:’center’,

buttons:[{

width : 100,

text : ‘提交’,

iconCls : ‘icon-ok’,

handler : function(t,e) {

t.setDisabled(true);

var form = me.down(‘form’).getForm();

var url = ‘project!savePro.action’;

if(row!=”)url = “project!update.action”;

if (form.isValid()) {

Ext.Ajax.request({

url : url,

params : form.getValues(),

success : function(response) {

var text = Ext.JSON.decode(response.responseText);

if (text.success) {

me.grid.getStore().load();

me.close();

} else {

t.setDisabled(false);

Ext.Msg.alert(‘提示’, ‘操作失敗’);

}

}

});

} else {

t.setDisabled(false);

Ext.MessageBox.alert(‘提示’, ‘請填寫正確的信息’);

}

}

},{

width : 100,

text : ‘重置’,

iconCls : ‘icon-reset’,

handler : function(t,e) {

me.down(‘form’).getForm().reset();

}

},

{

width : 100,

text : ‘退出’,

iconCls : ‘icon-cancel’,

handler : function(t,e) {

me.close();

}

}]

});

me.callParent(arguments);

}

});

java代碼:

package com.szusst.action.site;

import java.util.ArrayList;

import java.util.List;

import org.apache.struts2.json.annotations.JSON;

import com.opensymphony.xwork2.Action;

import com.szusst.entity.TBasMoniProject;

import com.szusst.service.BaseService;

public class ProjectAction implements Action{

private BaseService baseService;

private int limit;// 行數

private int start;// 開始行數

private int total;// 總數

private String key;

private ListTBasMoniProject list = new ArrayListTBasMoniProject(0);

private Boolean success;

private TBasMoniProject project = new TBasMoniProject();//這個是需要set方法和get方法–關鍵

private String proIds;

public String execute() {

int []num = {0};

list = baseService.queryProjects(limit, start, key, num);

total = num[0];

success = true;

return SUCCESS;

}

public String savePro() {

success = baseService.savePro(project);

return SUCCESS;

}

public String delete() {

long num = baseService.deletePro(proIds);

if(num0){

success = true;

}

return SUCCESS;

}

public String update() {

success = baseService.updatePro(project);

return SUCCESS;

}

public int getTotal() {

return total;

}

public ListTBasMoniProject getList() {

return list;

}

public Boolean getSuccess() {

return success;

}

public void setBaseService(BaseService baseService) {

this.baseService = baseService;

}

public void setLimit(int limit) {

this.limit = limit;

}

public void setStart(int start) {

this.start = start;

}

public void setKey(String key) {

this.key = key;

}

@JSON(serialize=false)

public TBasMoniProject getProject() {

return project;

}

public void setProject(TBasMoniProject project) {

this.project = project;

}

public void setProIds(String proIds) {

this.proIds = proIds;

}

}

實體類:

package com.szusst.entity;

import java.util.HashSet;

import java.util.Set;

/**

* TBasMoniProject entity. @author MyEclipse Persistence Tools

*/

public class TBasMoniProject{

// Fields

private Integer id;

private TOthSiteType siteType;

private String name;

private String code;

private String unit;

private Integer decimal;

private String maxNum;

private String minNum;

private String alarmNum;

private String mask;

private String guobiaoNo;

private String shujuMk;

private SetTBasMoniEquipment equips = new HashSetTBasMoniEquipment(0);

public TBasMoniProject() {

}

public Integer getId() {

return id;

}

public void setId(Integer id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getCode() {

return code;

}

public void setCode(String code) {

this.code = code;

}

public String getUnit() {

return unit;

}

public void setUnit(String unit) {

this.unit = unit;

}

public Integer getDecimal() {

return decimal;

}

public void setDecimal(Integer decimal) {

this.decimal = decimal;

}

public TOthSiteType getSiteType() {

return siteType;

}

public void setSiteType(TOthSiteType siteType) {

this.siteType = siteType;

}

public String getMaxNum() {

return maxNum;

}

public void setMaxNum(String maxNum) {

this.maxNum = maxNum;

}

public String getMinNum() {

return minNum;

}

public void setMinNum(String minNum) {

this.minNum = minNum;

}

public String getAlarmNum() {

return alarmNum;

}

public void setAlarmNum(String alarmNum) {

this.alarmNum = alarmNum;

}

public String getMask() {

return mask;

}

public void setMask(String mask) {

this.mask = mask;

}

public String getGuobiaoNo() {

return guobiaoNo;

}

public void setGuobiaoNo(String guobiaoNo) {

this.guobiaoNo = guobiaoNo;

}

public String getShujuMk() {

return shujuMk;

}

public void setShujuMk(String shujuMk) {

this.shujuMk = shujuMk;

}

public SetTBasMoniEquipment getEquips() {

return equips;

}

public void setEquips(SetTBasMoniEquipment equips) {

this.equips = equips;

}

}

配置文件:

action name=”project” class=”com.szusst.action.site.ProjectAction”

result name=”success” type=”json”/result

/action

然後就是配置好structs…..基本上就ok 。。。。

extjs+springMVC架構,前台多條記錄怎麼傳遞到後台且封裝成多個對象

簡單說下:1.用Ext.getCmp(“id”).getValue();等方法獲得當前界面中你想傳遞到後台的值; 2.用formpanel.form.doAction(‘submit’,{ url:’logic.jsp’, method:’post’, params:, //把需傳到後台的數據放在這裡。 success : function(form,action){ i

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/192926.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-01 10:31
下一篇 2024-12-01 10:31

相關推薦

  • Python讀取CSV數據畫散點圖

    本文將從以下方面詳細闡述Python讀取CSV文件並畫出散點圖的方法: 一、CSV文件介紹 CSV(Comma-Separated Values)即逗號分隔值,是一種存儲表格數據的…

    編程 2025-04-29
  • Python中讀入csv文件數據的方法用法介紹

    csv是一種常見的數據格式,通常用於存儲小型數據集。Python作為一種廣泛流行的編程語言,內置了許多操作csv文件的庫。本文將從多個方面詳細介紹Python讀入csv文件的方法。…

    編程 2025-04-29
  • 如何用Python統計列表中各數據的方差和標準差

    本文將從多個方面闡述如何使用Python統計列表中各數據的方差和標準差, 並給出詳細的代碼示例。 一、什麼是方差和標準差 方差是衡量數據變異程度的統計指標,它是每個數據值和該數據值…

    編程 2025-04-29
  • Python多線程讀取數據

    本文將詳細介紹多線程讀取數據在Python中的實現方法以及相關知識點。 一、線程和多線程 線程是操作系統調度的最小單位。單線程程序只有一個線程,按照程序從上到下的順序逐行執行。而多…

    編程 2025-04-29
  • Python爬取公交數據

    本文將從以下幾個方面詳細闡述python爬取公交數據的方法: 一、準備工作 1、安裝相關庫 import requests from bs4 import BeautifulSou…

    編程 2025-04-29
  • Python兩張表數據匹配

    本篇文章將詳細闡述如何使用Python將兩張表格中的數據匹配。以下是具體的解決方法。 一、數據匹配的概念 在生活和工作中,我們常常需要對多組數據進行比對和匹配。在數據量較小的情況下…

    編程 2025-04-29
  • Python數據標準差標準化

    本文將為大家詳細講述Python中的數據標準差標準化,以及涉及到的相關知識。 一、什麼是數據標準差標準化 數據標準差標準化是數據處理中的一種方法,通過對數據進行標準差標準化可以將不…

    編程 2025-04-29
  • 如何使用Python讀取CSV數據

    在數據分析、數據挖掘和機器學習等領域,CSV文件是一種非常常見的文件格式。Python作為一種廣泛使用的編程語言,也提供了方便易用的CSV讀取庫。本文將介紹如何使用Python讀取…

    編程 2025-04-29
  • Python根據表格數據生成折線圖

    本文將介紹如何使用Python根據表格數據生成折線圖。折線圖是一種常見的數據可視化圖表形式,可以用來展示數據的趨勢和變化。Python是一種流行的編程語言,其強大的數據分析和可視化…

    編程 2025-04-29
  • Python如何打亂數據集

    本文將從多個方面詳細闡述Python打亂數據集的方法。 一、shuffle函數原理 shuffle函數是Python中的一個內置函數,主要作用是將一個可迭代對象的元素隨機排序。 在…

    編程 2025-04-29

發表回復

登錄後才能評論