Skip to Content
Menu
This question has been flagged
1 Odpoveď
2013 Zobrazenia

In my JavaScript code, I would like to dynamically pass the ID in self.fetch_table_data("10") from the selectedEmployeeId obtained in the _onEmployeeChange function. How can I achieve this in the willStart function?

willStart: function() {
var self = this;
return $.when(this._super()).then(function() {
return self.fetch_data(), self.fetch_table_data("10");
});
},
_onEmployeeChange: function (event) {
var selectedEmployeeId = document.getElementById("resource_title").value;
this.fetch_table_data(selectedEmployeeId);
},

fetch_table_data: function(employee_id) {
var self = this;
var def2 = this._rpc({
model: 'project.project',
method: 'get_table_data',
args: [employee_id, ],
}).then(function(result1) {
self.resource_data = result1['table_data']
console.log(self.resource_data, "success")
self.drawGanttChart(self.resource_data)
});
return $.when(def2);
},


Avatar
Zrušiť
Best Answer

Hi,

The value is fetched after the dom is loaded in _onEmployeeChange function 

How ever In the onWillStart function there is no DOM so you cant get the id from the DOM element so you need to modify your onWillStart like this

willStart: function() {
  var self = this;
  return $.when(this._super()).then(function() {
        return self.fetch_data(), self.fetch_table_data(); //removed the hardcoded id
   });
},
And then change the fetch_table_data to something like this

fetch_table_data: function(employee_id) {
   var self = this;
   Var args = employee_id ?  [employee_id,] : []
   var def2 =  this._rpc({
          model: 'project.project',
          method: 'get_table_data',
          args,
   }).then(function(result1) {
       self.resource_data = result1['table_data']
       console.log(self.resource_data, "success")
       self.drawGanttChart(self.resource_data)
   });
   return $.when(def2);
},


And now you have to modify your server side to return a specific or random employee when called 'get_table_data' function without and id

class ProjectModel(models.Model):
_name = 'project.project'

@api.model
def get_table_data(self, employee_id=False):
# Your logic to return specific or random employee data
# Use employee_id if provided, otherwise fetch data for a specific or random employee
# ...

return {'table_data': your_processed_data}


Hope it helps


Avatar
Zrušiť
Related Posts Replies Zobrazenia Aktivita
1
mar 24
2163
2
mar 24
1802
0
feb 24
1461
0
sep 23
2167
8
nov 23
55145