为什么 Storage.getItemSync() 控制台不记录实际值?
Why Storage.getItemSync() doesn't console log the actual value?
var storage = require('node-persist');
storage.initSync();
storage.setItemSync('accounts', [{
bankname: 'Chase',
balance: 0}, {
bankname: 'Bofa',
balance: 0}
]);
var accounts = storage.getItemSync('accounts');
console.log('accounts are ' + accounts);
输出:
账户是[object Object],[object Object]
如何获取实际储值?
使用 node@5.4.1,node-persist@0.0.6
如果你想控制台正确记录列表或对象,你必须 json 字符串化对象。
console.log('accounts are ' + JSON.stringify(accounts));
如果您想分别对每个对象进行字符串化,则可以使用它。
accounts.forEach(function(acc){
console.log(JSON.stringify(acc));
})
var storage = require('node-persist');
storage.initSync();
storage.setItemSync('accounts', [{
bankname: 'Chase',
balance: 0}, {
bankname: 'Bofa',
balance: 0}
]);
var accounts = storage.getItemSync('accounts');
console.log('accounts are ' + accounts);
输出: 账户是[object Object],[object Object]
如何获取实际储值?
使用 node@5.4.1,node-persist@0.0.6
如果你想控制台正确记录列表或对象,你必须 json 字符串化对象。
console.log('accounts are ' + JSON.stringify(accounts));
如果您想分别对每个对象进行字符串化,则可以使用它。
accounts.forEach(function(acc){
console.log(JSON.stringify(acc));
})