BomberMan
BomberMan

Reputation: 1094

jQuery load .data to a child element

My index.html is here:

<tr class="activity_row" t-att-data-activity_id="activity.id">
   <td>
       <div>
           <t t-if="duration != undefine">
              <span class="pt_duration_line"><t t-esc="duration.split(':')[0] + 'h ' + (duration.split(':')[1] and duration.split(':')[1] + 'min' or '')"></t></span> <!-- call format_hour method of this screen -->
           </t>
       </div>
   </td>
</tr>

For first tr tag the onclick action is:

this.$el.find(".activity_row").on("click", this.on_row_click);

on_row_click: function(event) {
    var activity_id = $(event.currentTarget).data("activity_id");
    if(activity_id) {
        var activity = this.project_timesheet_db.get_activity_by_id(activity_id);
        this.project_timesheet_widget.screen_selector.set_current_screen("add_activity", activity);
    }
},

Here i am getting activity_id successfully. But Inside this row there is internal div which includes span as mentioned on top containing pt_duration_line class. And for this, onclick action is :

this.$el.find(".pt_duration_line").on("click", this.on_url_click);

    on_url_click: function(event) {
        var act_id = $(event.currentTarget).data("act_id");
        if(act_id) {
            var activity = this.project_timesheet_db.get_activity_by_id(act_id);

for this internal div I am not getting value of 'act_id' which I am getting for 'activity_id' for parent element row.

In brief: What to do if i want to get activity_id for the div resided in that row. Thanks in advance

Upvotes: 0

Views: 69

Answers (1)

erikrunia
erikrunia

Reputation: 2383

try this:

<tr class="activity_row" t-att-data-activity_id="activity.id">
   <td>
       <div>
           <t t-if="duration != undefine">
              <span class="pt_duration_line" t-att-data-act-id="activity.id"><t t-esc="duration.split(':')[0] + 'h ' + (duration.split(':')[1] and duration.split(':')[1] + 'min' or '')"></t></span> <!-- call format_hour method of this screen -->
           </t>
       </div>
   </td>
</tr>

also, as other users mentioned, e and event are not the same, change to this:

this.$el.find(".pt_duration_line").on("click", this.on_url_click);

    on_url_click: function(event) {
        var act_id = $(event.currentTarget).data("act_id");
        if(act_id) {
            var activity = this.project_timesheet_db.get_activity_by_id(act_id);

Upvotes: 1

Related Questions