查询脚本报错 TypeError: rows is undefined

本文详细解析了EasyUI查询页面在处理数据时出现的错误问题,特别是当查询结果为空时前台jQuery出现‘TypeError:rowsisundefined’错误的情况,并提供了相应的解决方法。通过在后台模型中增加判断与初始化逻辑,确保数据处理流程的稳定性和用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

easyui查询页面有数据不报错,没有数据前台报错:TypeError: rows is undefined。
分析原因:rows为查询结果集合,通过json进行数据转换为{'total':'总页数',rows:list集合}格式,当rows为null的时候,前台jQuery报错“TypeError: rows is undefined”。
解决办法:改写后台model,在getter方法中判断rows是否为空,赋初值。
示例:
public Long getTotal() {
if(total==null){
total=0L;
}
return total;
}
public List<T> getRows() {
if(rows==null){
rows=new ArrayList<T>();
}
return rows;
}
// 停止并重置Group Replication MySQL localhost:33060+ ssl JS > session.runSql('STOP GROUP_REPLICATION'); Query OK, 0 rows affected (0.0008 sec) MySQL localhost:33060+ ssl JS > session.runSql('RESET MASTER'); Session.runSql: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'MASTER' at line 1 (MySQL Error 1064) MySQL localhost:33060+ ssl JS > session.runSql('RESET SLAVE ALL'); Session.runSql: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SLAVE ALL' at line 1 (MySQL Error 1064) MySQL localhost:33060+ ssl JS > MySQL localhost:33060+ ssl JS > // 设置正确的GR组名 MySQL localhost:33060+ ssl JS > session.runSql(`SET GLOBAL group_replication_group_name = '9f8c6f7e-5652-11f0-a2e0-000c292cd265'`); Query OK, 0 rows affected (0.0310 sec) MySQL localhost:33060+ ssl JS > MySQL localhost:33060+ ssl JS > // 以引导模式启动 MySQL localhost:33060+ ssl JS > session.runSql('SET GLOBAL group_replication_bootstrap_group=ON'); Query OK, 0 rows affected (0.0113 sec) MySQL localhost:33060+ ssl JS > session.runSql('START GROUP_REPLICATION'); Query OK, 0 rows affected (1.4555 sec) MySQL localhost:33060+ ssl JS > session.runSql('SET GLOBAL group_replication_bootstrap_group=OFF'); Query OK, 0 rows affected (0.0004 sec) MySQL localhost:33060+ ssl JS > MySQL localhost:33060+ ssl JS > // 强制恢复集群 MySQL localhost:33060+ ssl JS > var cluster = dba.rebootClusterFromCompleteOutage("myCluster", { -> force: true, -> grGroupName: '9f8c6f7e-5652-11f0-a2e0-000c292cd265', // 显式指定GR组名 -> timeout: 120 -> }); -> Dba.rebootClusterFromCompleteOutage: Argument #2: Invalid options: grGroupName (ArgumentError) MySQL localhost:33060+ ssl JS > print("集群恢复成功:", cluster.status()); TypeError: Cannot read properties of undefined (reading 'status')
07-16
const express = require('express'); const cors = require('cors'); const sqlite3 = require('sqlite3').verbose(); const path = require('path'); // 创建服务器 const app = express(); app.use(express.json()); // 修复CORS配置 - 添加详细配置 app.use(cors({ origin: '*', methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], allowedHeaders: ['Content-Type', 'Authorization'], credentials: true })); // 处理预检请求 app.options('*', cors()); // 连接SQLite数据库 const db = new sqlite3.Database('./archive.db', (err) => { if (err) { console.error('数据库连接错误:', err.message); } else { console.log('成功连接SQLite数据库'); // 初始化档案表 db.run(`CREATE TABLE IF NOT EXISTS archives ( id INTEGER PRIMARY KEY AUTOINCREMENT, fileNumber TEXT NOT NULL, documentNumber TEXT, responsiblePerson TEXT, title TEXT NOT NULL, date TEXT, projectDate TEXT, securityLevel TEXT, pages INTEGER, retentionPeriod TEXT, carrierForm TEXT, notes TEXT, type TEXT NOT NULL, createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP, UNIQUE(fileNumber, type) )`); } }); // 获取档案数据 (添加错误处理) app.get('/api/archives', (req, res) => { const type = req.query.type || 'document'; db.all('SELECT * FROM archives WHERE type = ? ORDER BY createdAt DESC', [type], (err, rows) => { if (err) { console.error('数据库查询错误:', err); res.status(500).json({ error: '数据库查询失败' }); } else { res.json(rows); } }); }); // 添加新档案 app.post('/api/archives', (req, res) => { const { fileNumber, documentNumber, responsiblePerson, title, date, projectDate, securityLevel, pages, retentionPeriod, carrierForm, notes, type } = req.body; // 验证必填字段 if (!fileNumber || !title || !type) { return res.status(400).json({ error: '档号、题名和类型为必填项' }); } const sql = ` INSERT INTO archives ( fileNumber, documentNumber, responsiblePerson, title, date, projectDate, securityLevel, pages, retentionPeriod, carrierForm, notes, type ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) `; const values = [ fileNumber, documentNumber || null, responsiblePerson || null, title, date || null, projectDate || null, securityLevel || null, pages ? parseInt(pages) : null, retentionPeriod || null, carrierForm || null, notes || null, type ]; db.run(sql, values, function(err) { if (err) { // 处理唯一键冲突(档号重复) if (err.code === 'SQLITE_CONSTRAINT') { return res.status(409).json({ error: '该档号已存在,请使用其他档号' }); } return res.status(500).json({ error: err.message }); } res.status(201).json({ id: this.lastID, ...req.body }); }); }); // 更新档案 app.put('/api/archives/:id', (req, res) => { const id = req.params.id; const { fileNumber, documentNumber, responsiblePerson, title, date, projectDate, securityLevel, pages, retentionPeriod, carrierForm, notes, type } = req.body; // 验证必填字段 if (!fileNumber || !title || !type) { return res.status(400).json({ error: '档号、题名和类型为必填项' }); } const sql = ` UPDATE archives SET fileNumber = ?, documentNumber = ?, responsiblePerson = ?, title = ?, date = ?, projectDate = ?, securityLevel = ?, pages = ?, retentionPeriod = ?, carrierForm = ?, notes = ?, type = ? WHERE id = ? `; const values = [ fileNumber, documentNumber || null, responsiblePerson || null, title, date || null, projectDate || null, securityLevel || null, pages ? parseInt(pages) : null, retentionPeriod || null, carrierForm || null, notes || null, type, id ]; db.run(sql, values, function(err) { if (err) { // 处理唯一键冲突(档号重复) if (err.code === 'SQLITE_CONSTRAINT') { return res.status(409).json({ error: '该档号已存在,请使用其他档号' }); } return res.status(500).json({ error: err.message }); } if (this.changes === 0) { return res.status(404).json({ error: '档案未找到' }); } res.json({ id: id, ...req.body }); }); }); // 删除档案 app.delete('/api/archives/:id', (req, res) => { const id = req.params.id; db.run('DELETE FROM archives WHERE id = ?', [id], function(err) { if (err) { return res.status(500).json({ error: err.message }); } if (this.changes === 0) { return res.status(404).json({ error: '档案未找到' }); } res.json({ success: true }); }); }); // 批量导入档案 app.post('/api/archives/batch-import', (req, res) => { const data = req.body.data || []; if (data.length === 0) { return res.status(400).json({ error: '没有提供导入数据' }); } let insertedCount = 0; let skippedCount = 0; let processed = 0; // 开始事务 db.serialize(() => { db.run('BEGIN TRANSACTION'); data.forEach(item => { const { fileNumber, documentNumber, responsiblePerson, title, date, projectDate, securityLevel, pages, retentionPeriod, carrierForm, notes, type } = item; // 检查是否已存在相同档号和类型的档案 db.get('SELECT id FROM archives WHERE fileNumber = ? AND type = ?', [fileNumber, type], (err, row) => { if (err) { // 错误处理 return; } if (row) { // 跳过已存在的档案 skippedCount++; checkComplete(); return; } // 插入新档案 const sql = ` INSERT INTO archives ( fileNumber, documentNumber, responsiblePerson, title, date, projectDate, securityLevel, pages, retentionPeriod, carrierForm, notes, type ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) `; const values = [ fileNumber, documentNumber || null, responsiblePerson || null, title, date || null, projectDate || null, securityLevel || null, pages ? parseInt(pages) : null, retentionPeriod || null, carrierForm || null, notes || null, type ]; db.run(sql, values, function(err) { if (!err) { insertedCount++; } checkComplete(); }); }); }); function checkComplete() { processed++; if (processed === data.length) { db.run('COMMIT', (err) => { if (err) { return res.status(500).json({ error: '导入失败' }); } res.json({ insertedCount, skippedCount }); }); } } }); }); // 启动服务器 const port = 3000; app.listen(port, () => { console.log(`服务器运行在 http://localhost:${port}`); }); 运行这个js文件报错,throw new TypeError(`Missing parameter name at ${i}: ${DEBUG_URL}`);
最新发布
07-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值