0

I need to save some data in a param via Js. When I try to reuse the data, the param I get would be a proxy() obj, and I can not access the data of it. For example: in my .js file:

@track
historyData = []

method() {
  var item = {}
  item.id = 'a'
  item.data = 'xxx'
  this.historyData.push(item)
} 

get() {
  // here I get a proxy() object, the data is saved in originalTarget.
  this.historyData.find(item => item.id === 'a').data 
}

enter image description here

any solution?

2

This is how LWC or as a matter all Lightning components work.

Your code works fine. I created a button to check and it gave correct xxx

@track
historyData = []

connectedCallback() {
    this.pushToHistory();
}

pushToHistory() {
    var item = {};
    item.id = 'a';
    item.data = 'xxx';
    this.historyData.push(item);
}


handleButtonClick() {
    this.historyData.find(item => item.id === 'a').data;
}

Your code might be breaking elsewhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.