1

I'm trying to remove dynamicaly a Quicklaunch item in SharePoint 2010 (SandBoxed) using javascript Client object Model.

The code runs correctly. The selected item is deleted from my current quickLaunchNodeCollection but when I reload my quickLaunchNodeCollection the selected item is still existing.

function RemoveQuickLaunchNode() {
  var clientContext = new SP.ClientContext('/');
  this.nodeToRemove = this.quickLaunchNodeCollection.get_item(8);
  this.nodeToRemove.deleteObject();

  clientContext.executeQueryAsync(Function.createDelegate(this, this.onRefresh), Function.createDelegate(this, this.Failedmsg));
 }

Someone can help me ??

Thanks .

Miky_g971
  • 13
  • 6
  • Changes are like not persisted. – Miky_g971 Nov 14 '11 at 19:38
  • what is that you are trying to remove? if it is list or library there is a easy way to do it. – xgencoder Nov 14 '11 at 20:11
  • What do you mean with "when I reload my quickLaunchNodeCollection"? You mean you reload the page? Javascript is not persisted, that is correct. Or you mean that the change to quickLaunchNodeCollection is not persisted in Javascript? What is `nodeToRemove`? `NavigationNodeCollection` does not contain a delete in its JS form: http://msdn.microsoft.com/en-us/library/ff408721.aspx – Dennis G Nov 14 '11 at 21:28
  • @xgencoder , I'm trying to remove a quicklaunch Node. List or library does not matter to me, that can be both. – Miky_g971 Nov 15 '11 at 16:35
  • @moontear, `nodeToRemove` is a `NavigationNode`: [link](http://msdn.microsoft.com/en-us/library/ee557742.aspx). I have a GetQuickLaunchNode function which retrieve all quicklaunchNode(from server). This function fill `quickLaunchNodeCollection`. Then I want to remove a item from quickLaunchNodeCollection, so I use RemoveQuickLaunchNode function. To refresh(reload) I use GetQuickLaunchNode function another time. There is not Postback. – Miky_g971 Nov 15 '11 at 16:36
  • That's was a context problem. Current `clientContext` and `quickLaunchNodeCollection` are not same, so `nodeToRemove` can't be deleted. `function RemoveQuickLaunchNode() { this.nodeToRemove = this.quickLaunchNodeCollection.get_item(8); this.nodeToRemove.deleteObject(); //currentcontext is quickLaunchNodeCollection context currentcontext.executeQueryAsync(Function.createDelegate(this, this.onRefresh), Function.createDelegate(this, this.Failedmsg)); }` Thanks JAB. – Miky_g971 Nov 15 '11 at 22:30

1 Answers1

0

It was a context problem. clientContext and quickLaunchNodeCollection have not the same context, so nodeToRemove can't be deleted.

Miky_g971
  • 13
  • 6