In my Meteor app, I have the following table which shows some info. Users can edit company name, address and email and save the changes by clicking the button beside.
<table class="table table-hover">
<thead>
<tr>
<th>Company Name</th>
<th>Company Address</th>
<th>Email Address</th>
<th>Last Login</th>
<th>Manage</th>
</tr>
</thead>
<tbody>
{{#each users}}
<tr>
<td><input type="text" name="companyName" value="{{companyName}}"></td>
<td><input type="text" name="companyAddress" value="{{companyAddress}}"></td>
<td><input type="text" name="companyEmail" value="{{profile.email}}"></td>
<td>{{date}}</td>
<td><input type="submit" class="btn btn-primary save" value="Save">
<input type="submit" class="btn btn-danger delete" value="Delete"></td>
</tr>
{{/each}}
</tbody>
</table>
In event handler:
'click .save':function(e,inst){
var userID = this._id;
var companyName = inst.$('[name=companyName]').val();
var companyAddress = inst.$('[name=companyAddress]').val();
var companyEmail = inst.$('[name=companyEmail]').val();
console.log(companyName);
console.log(userID);
console.log(companyAddress);
console.log(companyEmail);
}
By doing so, It only can read the values of the first row of table. Then I add data-id in input field <td><input type="text" name="companyName" value="{{companyName}}" data-id="{{_id}}"></td>
It is able to get company name from the table row. My question is how to do with the rest of attributes.