首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >w2ui & Node Postgres数据库连接

w2ui & Node Postgres数据库连接
EN

Stack Overflow用户
提问于 2020-02-11 05:13:30
回答 1查看 83关注 0票数 0

嘿,我正在用w2ui编码一个项目,我试图从postgres数据库中获取数据,并将其显示在w2ui上的网格中,我所做的到数据库的连接是成功的,但是它的格式不同于预期的w2ui grid.Which应该是tableitem:"tabledata“我如何完成这一点。下面是我的queries.js代码

代码语言:javascript
复制
const Pool = require('pg').Pool
const pool = new Pool({
  user: 'postgres',
  host: 'jdbc:postgresql://172.24.143.61/ayelab_data',
  database: 'ayelab_data',
  password: '*****',
  port: 5432,
})

const getOrders = (request, response) => {
    pool.query('SELECT branchcode,ordercode,patient_lastname,patient_firstname,doctorsname,date_entered,departuredate,urgent,status FROM orders', (error, results) => {
      if (error) {
        throw error
      }
      response.status(200).json(results.rows)
    })
  }

  module.exports = {
    getOrders,

  }

这是我的w2ui网格代码

代码语言:javascript
复制
$(function () {
    $('#grid').w2grid({ 
        name: 'grid', 

        columns: [      
            { field: 'blank', caption: '', size: '10px' },          
            { field: 'branch', caption: 'Branch', size: '120px' },
            { field: 'order', caption: 'Order',size: '120px', editable: { type: 'text' }},
            { field: 'lname', caption: 'Last Name', size: '120px', editable: { type: 'text' } },
            { field: 'fname', caption: 'First Name', size: '120px', editable: { type: 'text' } },
            { field: 'physician', caption: 'Physician', size: '120px' },
            { field: 'dateadded', caption: 'Date Added', size: '120px',editable: { type: 'date' } },
            { field: 'completdate', caption: 'Completion Date', size: '120px',editable: { type: 'date' }},
            { field: 'priority', caption: 'Priority', size: '120px' },
            { field: 'status', caption: 'Status', size: '120px' }
        ]

    });  
    w2ui['grid'].load('node-api-postgres/queries.js');  
});
EN

回答 1

Stack Overflow用户

发布于 2020-02-14 00:04:33

我总是回答我自己的问题...将主机更改为host: '172.24.143.61',,并在请求中调用getOrder函数

代码语言:javascript
复制
app.get('/queries',(response,resp) => {
  db.getOrders(response,resp);
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60158525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档