Javascript .使用数据重定向进行传播

Javascript .使用数据重定向进行传播,javascript,promise,Javascript,Promise,在开发数据库时,方法spread是必不可少的,它将数组值转换为命名参数 但是,当解析的数据无法直接映射时,如何执行相同的操作 下面是嵌套事务的一个简单示例: db.tx(function () { return promise.all([ this.none("update users set active=$1 where id=$2", [true, 123]), this.none("insert into audit(status, id) val

在开发数据库时,方法
spread
是必不可少的,它将数组值转换为命名参数

但是,当解析的数据无法直接映射时,如何执行相同的操作

下面是嵌套事务的一个简单示例:

db.tx(function () {
    return promise.all([
        this.none("update users set active=$1 where id=$2", [true, 123]),
        this.none("insert into audit(status, id) values($1, $2)", ['active', 123]),
        this.tx(function () {
            return promise.all([
                this.one("insert into users(name) values($1) returning id", "John"),
                this.one("insert into events(code) values($1) returning id", 123)
            ]);
        })
    ]);
})
    .then(function (data) {
        console.log(data[2][0].id); // print new user id;
        console.log(data[2][1].id); // print new event id;
    });
我确实希望能够用
排列
替换最后一个
然后
部分,但问题是我们不能直接使用数据,我们需要在示例中使用
数据[2]

建议采用什么方法来实现以下效果:

.spread(data[2], function (user, event) {
    console.log(user.id); // print new user id;
    console.log(event.id); // print new event id;
});
你可以用

.get(2).spread(function(user, event) { ... })