0

I delete elements stored in simple-storage array in main script.This creates null elements in the simple-storage array.So i run a script to return a new array to the main addon script (which contains no null elements) and i assign it to simple-storage array.But the main script gets only one element not the entire array. How to get the entire array? below is the main addon code part:

text_entry.port.on("del", function (todel) {
  console.log(todel);
  site_l=ss.storage.sites.length;

  for(var i=0;i<site_l;i++)
  {
    if(ss.storage.sites[i]==todel)
    {
        delete ss.storage.sites[i];
    }   
  }
  text_entry.port.emit("c",ss.storage.sites);
  text_entry.port.on("cd",function(arr){
    ss.storage.sites=[];
    ss.storage.sites=arr;
  });

});

script which returns new array containing no null elements:

self.port.on("c",function(arr)
{
    var a=arr;
    var l=a.length;

    function isEmpty(element) {
    if(element!=null)
      return true;
    }

    a=a.filter(isEmpty);
    self.port.emit("cd",a);
});
3
  • It's hard to tell what you're doing here - is text_entry a page-mod instance, or what? Can you provide a reduced example that people could run and test for themselves? Commented Feb 13, 2014 at 22:34
  • if you have a non-sdk version i can help you out. can you make a simple test case, i can make a demo addon for you. Commented Feb 14, 2014 at 17:07
  • @canuckistani its panel instance. User selects items from a list in panel and clicks delete button which makes the panel content script to get and store the selected items from the list in a local array.And now it needs to send that array to the main script.I found a way. Convert the array to string and pass it to main script and use split to make it an array. Commented Feb 15, 2014 at 4:18

1 Answer 1

1

Replace

for(var i=0;i<site_l;i++) {
  if(ss.storage.sites[i]==todel) {
    delete ss.storage.sites[i];
  }   
}

With ss.storage.sites.splice(ss.storage.sites.indexOf(todel), 1)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.