Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 有条件地设置对象属性_Javascript_If Statement_Dynogels - Fatal编程技术网

Javascript 有条件地设置对象属性

Javascript 有条件地设置对象属性,javascript,if-statement,dynogels,Javascript,If Statement,Dynogels,如果queryString为null,是否可以删除.where子句 我在表达式中间尝试了三元算子,但不起作用。 此外,equals表达式不允许:null、未定义或空字符串 CashierHistory .scan() .where('userId').equals(path['userId']) .where('status').equals(queryString['status']) # remove all this

如果queryString为null,是否可以删除.where子句

我在表达式中间尝试了三元算子,但不起作用。

此外,equals表达式不允许:null、未定义或空字符串

CashierHistory
            .scan()
            .where('userId').equals(path['userId'])
            .where('status').equals(queryString['status']) # remove all this line in case of queryString['status'] is null
            .limit(10)
            .startKey(queryString)
            .exec(function (err, acc) {
                if (err == null) {
                    console.log(acc);
                    return cb(null, Api.response(acc));
                } else {
                    console.log(err['message']);
                    return cb(null, Api.errors(200, {5: err['message']}));
                }
            });

编辑:我正在使用(Dynamodb的ORM)

正如丹达维斯所说,您可以将查询分为两部分

var query = CashierHistory
        .scan()
        .where('userId').equals(path['userId']);

if (queryString['status']) {
    query = query.where('status').equals(queryString['status']);
}

return query.limit(10)
        .startKey(queryString)
        .exec(function (err, acc) {
            if (err == null) {
                console.log(acc);
                return cb(null, Api.response(acc));
            } else {
                console.log(err['message']);
                return cb(null, Api.errors(200, {5: err['message']}));
            }
        });

您正在使用的库或类似库是什么?在条件之前/之后分成两部分,将左侧指定给变量,添加IF,使用命名的var@T.J.Crowder编辑我的question@dandavis我不喜欢这样做,因为我需要做很多的if/else,因为我将有4个条件,然后将是16 if/else