Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
2012 Представления

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


Аватар
Отменить
Лучший ответ

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


Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
мар. 24
2162
2
мар. 24
1802
0
февр. 24
1461
0
сент. 23
2167
8
нояб. 23
55137