如何获取特定值onblur的关键字以更新角度2

时间:2016-03-14 13:35:50

标签: angular

我需要动态密钥(在typescript“pax_traveling_c”中给出,这是硬编码的),所以我可以在点击特定的contentEditable字段时编辑多个值,并根据其键更改它的值,我如何获得特定值的键。

在json中有很多键都有,所以我想要键名,因为我必须根据这些键更新值,例如;我只放了一个键(“pax_traveling_c”)。 请帮帮我。

Html查看:

<table *ngIf="opportunity" class="table table-responsive table-bordered">
     <tbody>
       <tr>
          <td class="head">Start Date of Trip</td>
          <td class="details" contentEditable="true [(contenteditableModel)]="opportunity[0].date_of_tour_start_c" >{{opportunity[0].date_of_tour_start_c}}</td>
       </tr>
       <tr>
          <td class="head">End Date of Trip</td>
          <td contenteditable="true" class="details" [(contenteditableModel)]="opportunity[0].date_closed">{{opportunity[0].date_closed}}</td>
       </tr>
       <tr>
          <td class="head">Number of Rider</td>
          <td contenteditable="true" class="details" [(contenteditableModel)]="opportunity[0].pax_traveling_c">{{opportunity[0].pax_traveling_c}}</td>
       </tr>
   </tbody>
 </table>

Controller (typescript) :
rider-update.ts

  onBlur(opportunityById) {
      let id =  this._routeParams.get("id");
      this._opportunityService.setOpportunity(opportunityById)  
                .subscribe(
                      opportunityById = {
                         "id": this._routeParams.get("id"),
                         "pax_traveling_c": opportunity =>   this.opportunity = opportunity
                            },
                         error =>  this.errorMessage = <any>error);
  }

 Service (typescript):

 export class OpportunityService {

   private _opportunitiesUpdateUrl= '/api/oppurtunities/updates';

   setOpportunity(opportunity:Opportunity){
    let body = JSON.stringify({ opportunity });
    let headers = new Headers({ 'Content-Type': 'application/json' });
    let options = new RequestOptions({ headers: headers });
    return this.http.post(this._opportunitiesUpdateUrl, body, options)
        .map(res => res.json())
        .do(data => console.log(data)) // eyeball results in the console
        .catch(this.handleError);
    }
 }
json :
{
  account_id: "e327324f-92e6-cadc-d8aa-55922e65d917"
  account_name: "Test"
  amount: "399"
  amount_usdollar: "399"
  id: "e085d259-ca88-4e9f-c78f-563073a2f440"
  pax_traveling_c: "99"
  probability: "23"
  sales_stage: "Needs Analysis"
}

0 个答案:

没有答案