Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/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 单击后在Json上创建新对象(http.put)_Javascript_Json_Angular - Fatal编程技术网

Javascript 单击后在Json上创建新对象(http.put)

Javascript 单击后在Json上创建新对象(http.put),javascript,json,angular,Javascript,Json,Angular,我有以下json结构: "disputas": [ { id: "", tipo_negociacao: "", historico:{ fl_usuario: "", created_at: "", updated_at: "", created_by: null, updated_by: null, texto: "", }

我有以下json结构:

"disputas": [
    {
      id: "",
      tipo_negociacao: "",
      historico:{
         fl_usuario: "",
         created_at: "",
         updated_at: "",
         created_by: null,
         updated_by: null,
         texto: "",
      }
    }
]
我正在使用http.put更新这个json,我想在每次单击按钮时创建另一个historico对象,所以它看起来像这样:

"disputas": [
    {
      id: "",
      tipo_negociacao: "",
      historico:{
         fl_usuario: "",
         created_at: "",
         updated_at: "",
         created_by: null,
         updated_by: null,
         texto: "",
      },
         historico:{
         fl_usuario: "",
         created_at: "",
         updated_at: "",
         created_by: null,
         updated_by: null,
         texto: "",
      }
    }
]
我该怎么做

这是我的服务:

url: string = 'http://localhost:3004/disputa';
constructor(private http: Http){}
atualizaDisputa (body:Object): Observable<DisputaPropostaComponent[]>{
    let bodyString = JSON.stringify(body); // Stringify payload
    let headers      = new Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON
    let options       = new RequestOptions({ headers: headers }); // Create a request option
    return this.http.put(`${this.url}/${body['id']}`, body, options) // ...using post request
                     .map((res:Response) => res.json()) // ...and calling .json() on the response to return data
                     .catch((error:any) => Observable.throw(error.json().error || 'Ocorreu um erro em nosso servidor, tente novamente mais tarde')); //...errors if any
}

提前谢谢。如果你们需要更多代码,请告诉我。

对象上不能有两个名为historico的键。您需要将其转换为数组。一旦这样做了,您就可以像往常一样推到阵列上

你的问题不清楚。你想创建这样的东西:historico:{fl_usuario:,created_at:,updated_at:,created_by:null,updated_by:null,texto:,}当按下按钮时?我刚刚编辑了这个问题,我想现在更清楚了,一个物体上不能有两把名为historico的钥匙。您需要将其转换为数组。一旦你这样做了,你就可以像往常一样推到阵列上。哦,是的,没错。对不起,我弄糊涂了。我用数组来做。谢谢