感谢答复,我是小白在javascript节点
When you define getResult function, you're doing it inside of a function's clousure. Which means that, this function will be only accessible inside that function.
是可访问的,如果我们使用全局变量?
对象C有attribut
console.log(c);
Client {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
_handle: ClientBinding {},
_config: { host: '127.0.0.1', user: 'root', password: 'maria', db: 'gim' },
_req: undefined,
_queue:
[ { cb: [Function],
result: undefined,
results: undefined,
metadata: undefined,
str: 'SELECT * FROM contact WHERE id = \'4\' AND nom = \'dupont\'',
needColumns: true,
needMetadata: false,
rowBuilder: undefined } ],
_queryCache:
LRUCache {
_max: 30,
_lengthCalculator: [Function: naiveLength],
_allowStale: false,
_maxAge: null,
_dispose: [Function: EMPTY_LRU_FN],
_cache: { 'SELECT * FROM contact WHERE id = ? AND nom = ?': [Object] },
_lruList: { '0': [Object] },
_mru: 1,
_lru: 0,
_length: 1,
_itemCount: 1 },
_handleClosing: false,
_tmrInactive: undefined,
_tmrPingWaitRes: undefined,
connecting: true,
connected: false,
closing: true,
threadId: undefined,
_firstQuery:
{ str: 'SELECT CONNECTION_ID()',
cb: [Function: cb],
result: undefined,
results: undefined,
needMetadata: false,
needColumns: false } }
是不可能直接在属性objet客户端注入数据?
c.query('SELECT * FROM contact WHERE id = ? AND nom = ?', [ 4, 'dupont' ], function(err, rows) {
if (err){
throw err;
}else{
c.results = function(err,rows){
return rows;
}
}
});
也许:'rows = c.query(... return rows ...);'? –