为什么通过JSON.stringify转化出来的字符串创建记录会出错,而直写入内容{ id: 5, title: 'Some Title 5', body: 'Some body 5' }可以正常。
var FastLegSBase = require('FastLegS');
var FastLegS = new FastLegSBase('mysql');
var connectionParams = {
user: 'root', password: '',
database: 'warship', host: 'localhost', port: 3306
}
FastLegS.connect(connectionParams);
var callback = function(err, results) {
console.dir(err);
console.dir(results);
}
var PlayerTables = FastLegS.Base.extend({
tableName: 'player',
primaryKey: 'id'
});
var info = JSON.stringify(player.info);
PlayerTables.create(info, callback);
为什么我通过JSON.stringify转化出来的字符串创建记录会出错,而直写入内容{ id: 5, title: 'Some Title 5’, body: ‘Some body 5’ }可以正常。
8 回复
有错误提示,看不懂
E:\Server\node_modules\FastLegS\lib\utils.js:30
return _.include(columns, field.split('.')[0]);
^
TypeError: Object 0 has no method 'split'
at fieldIsValid (E:\Server\node_modules\FastLegS\lib\utils.js:30:37)
at E:\Server\node_modules\FastLegS\lib\utils.js:92:16
at Function._.each._.forEach (E:\Server\node_modules\FastLegS\node_modules\underscore\underscore.js:81:22)
at _.(anonymous function) [as each] (E:\Server\node_modules\FastLegS\node_modules\underscore\underscore.js:1069:39)
at validFields (E:\Server\node_modules\FastLegS\lib\utils.js:91:15)
at E:\Server\node_modules\FastLegS\lib\adapters\mysql\statements.js:83:17
at Array.map (native)
at Function._.map._.collect (E:\Server\node_modules\FastLegS\node_modules\underscore\underscore.js:97:56)
at buildInsertFields (E:\Server\node_modules\FastLegS\lib\adapters\mysql\statements.js:82:14)
at Object.exports.insert (E:\Server\node_modules\FastLegS\lib\adapters\mysql\statements.js:36:16)
TypeError: Object 0 has no method ‘split’ 的意思是,field变量没有一个叫split的方法。 split只有字符串才有的,而此时的field是一个数值型。
这个错误有可能是FastLegS模块的Bug,也有可能是因为其他地方的输入不正确而引发的。