Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie

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);
},


Awatar
Odrzuć
Najlepsza odpowiedź

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


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
mar 24
2184
2
mar 24
1814
0
lut 24
1480
0
wrz 23
2174
8
lis 23
55177