İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
2034 Görünümler

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
Vazgeç
En İyi Yanıt

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
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Mar 24
2197
2
Mar 24
1828
0
Şub 24
1492
0
Eyl 23
2178
8
Kas 23
55222