跳至內容
選單
此問題已被標幟
1 回覆
2011 瀏覽次數

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


頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
3月 24
2161
2
3月 24
1801
0
2月 24
1461
0
9月 23
2167
8
11月 23
55126