不能使用变量作为参数

时间:2016-11-22 12:59:16

标签: json angular typescript filter

我试图在这个网址中插入参数,但我无法让它工作。这是我的代码:

   filterFunction(newValue, parameter){
    this.workorderservice.searchWorkorders(1, 20, {sort: {}, search: {predicateObject: {'workorder.location.street': newValue}}, pagination: {start: 0}})

        .subscribe(data =>{ this.rows = data.json()
            this.links = this.parselink.parse(data.headers.get('link'))
            console.log(this.rows)
        })

}

我尝试替换' workorder.location.street'使用参数

1 个答案:

答案 0 :(得分:2)

您不能使用这样的参数名称。即使你的问题有点模糊,我想你应该这样做:

   filterFunction(newValue, parameter) {

     let predicateObject: any = {};
     predicateObject[parameter] = newValue;

     this.workorderservice.searchWorkorders(1, 20, {sort: {}, search: {predicateObject: predicateObject}, pagination: {start: 0}})

        .subscribe(data =>{ this.rows = data.json()
            this.links = this.parselink.parse(data.headers.get('link'))
            console.log(this.rows)
        })

    }