Jquery 续集创建错误

Jquery 续集创建错误,jquery,node.js,express,sequelize.js,Jquery,Node.js,Express,Sequelize.js,我试图弄清楚如何使用bulkCreate方法处理jQuery字段值。目前,我正在尝试传递数组中字段的值,并希望将每个值解析为一个新记录,但该方法似乎不是这样工作的,因此我收到一个错误: Error during Post: SequelizeDatabaseError: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versi

我试图弄清楚如何使用bulkCreate方法处理jQuery字段值。目前,我正在尝试传递数组中字段的值,并希望将每个值解析为一个新记录,但该方法似乎不是这样工作的,因此我收到一个错误:

Error during Post: SequelizeDatabaseError: ER_PARSE_ERROR: 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 '['Test 1','Test 2','Test 3'],'6','2016-02-01 03:26:59','2016-02-01 03:26:59')' at line 1
这是因为我实际上应该在路由中应用循环逻辑来处理不同的值吗?我应该更改jQuery吗

查看文件(discoveryName是bulkCreate的字段):

DiscoverySource模型字段:

    discoverySourceId: {
        type: DataTypes.INTEGER,
        field: 'discovery_source_id',
        autoIncrement: true,
        primaryKey: true
    },
    discoverySource: {
        type: DataTypes.STRING,
        field: 'discovery_source'
    },
    organizationId: {
        type: DataTypes.TEXT,
        field: 'organization_id'
    },

使用
.bulkCreate
您需要传递一个对象数组,该数组将转换为行

.post(function(req, res){
    var sources = _.map(req.body.discoverySource, function (source) {
        return {
             discoverySource: source,
             organizationId: req.body.organizationId
        };
    });
    models.DiscoverySource.bulkCreate(sources)
    .then(function(){
        return models.DiscoverySource.findAll();
    }).then(function(discoverySource){
        console.log(discoverySource);
        res.redirect('/app');
    }).catch(function(error){
        res.send(error);
        console.log('Error during Post: ' + error);
    });
});

嘿,Ben,我很感谢你的回答,但是看来return语句在
return{discoverySource:src,organizationId:req.body,organizationId}处抛出了一个语法错误
语法错误:意外标记}
。有什么想法吗?你介意在我的
.post
路线的上下文中写下这个答案,这样我就可以正确地实现它了吗?我很感激编辑,但我现在在
$
遇到了一个错误<代码>引用错误:$未定义
任何想法?@cphill这通常是访问jQuery的方式。我不知道你们的应用程序是如何设置的,但因为它看起来像节点,我可能只需要引入loDash。var=要求('lodash');然后,您可以使用相同的代码,只需替换u.each(),嘿,Ben,这解决了我的问题,但似乎没有在函数中传递值。post方法插入一条记录,记录表单中存在的字段数量,但我得到的值为NULL。console.log中的值是从
req.body.discoverySource
传递的值,但它似乎没有将该值传递给变量。我应该为此提出一个新问题吗?['Test Source']
正在执行(默认):插入到
discovery\u Source`(
discovery\u Source\u id
createdAt
updatedAt
)值(NULL,'2016-02-07 20:29:24','2016-02-07 20:29:24')`
    discoverySourceId: {
        type: DataTypes.INTEGER,
        field: 'discovery_source_id',
        autoIncrement: true,
        primaryKey: true
    },
    discoverySource: {
        type: DataTypes.STRING,
        field: 'discovery_source'
    },
    organizationId: {
        type: DataTypes.TEXT,
        field: 'organization_id'
    },
.post(function(req, res){
    var sources = _.map(req.body.discoverySource, function (source) {
        return {
             discoverySource: source,
             organizationId: req.body.organizationId
        };
    });
    models.DiscoverySource.bulkCreate(sources)
    .then(function(){
        return models.DiscoverySource.findAll();
    }).then(function(discoverySource){
        console.log(discoverySource);
        res.redirect('/app');
    }).catch(function(error){
        res.send(error);
        console.log('Error during Post: ' + error);
    });
});