Below you will find pages that utilize the taxonomy term “SP.js”
Posts
Parameterize a javascript object and create url
If you want to add some parameters to an url which you want to open, you can use jQuery.param function:
var url = "some\_url"; var params = { name: "Setner", email: "setner@narspi.name", mobile: "123456789" }; var search = "?" + $.param(p); url += search; ```It is handy, indeed. In an environment without jQuery (are there some?:) ) you can just iterate an object and join properties: var url = “some_url”; var params = { name: “Setner”, email: “setner@narspi.
Posts
Pass arguments from/to Modal Dialog
To pass arguments from a ModalDialog is easy. Provide some buttons and invoke close function:
SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, someValue); ```The first argument is result, [it is a enumeration with three alternatives](http://msdn.microsoft.com/en-us/library/ff409060.aspx): cancel, invalid and OK. The value you pass back to the main window can be a simple string, or a complex javascript object. In this example I'll create a html element which is hidden (id="modal-form" [class="s4-die"](/2011/10/14/s4-die/)): Pass arguments to Modal Dialog and use it In options you pass to SP.
Posts
Vänta tills sp.js laddats
Här är en funktion som man kan använda för att vänta till sp.js laddats och köra sin funktion:
ExecuteOrDelayUntilScriptLoaded(myjsfucntion, "sp.js"); Eftersom det kan vara så att sp.js laddas med lazy loading:
<SharePoint:ScriptLink Name="SP.js" runat="server" OnDemand="true" Localizable="false"
Posts
Uppdatera web med js
Här är ett litet exempel:
function updateTitle() { var ctx = new SP.ClientContext.get\_current(); this.web = ctx.get\_web(); web.set\_title('Examensarbete 2011'); this.web.update(); ctx.executeQueryAsync( Function.createDelegate(this, this.onUpdate), Function.createDelegate(this, this.onFail)); } function onUpdate(sender, args) { alert('title updated'); } function onFail(sender, args) { alert('failed to update title. Error:'+args.get\_message()); }
Posts
javascript API i Sharepoint
Det är supersmidigt. Här är ett exempel: function createAnnouncement(title, body) { var ctx = new SP.ClientContext.get\_current(); var list = ctx.get\_web().get\_lists().getByTitle('Meddelanden'); var itemCreationInfo = new SP.ListItemCreationInformation(); this.newListItem = list.addItem(itemCreationInfo); this.newListItem.set\_item("Title", title); this.newListItem.set\_item("Body", body); this.newListItem.update(); ctx.executeQueryAsync( Function.createDelegate(this, this.onSucceededCallback), Function.createDelegate(this, this.onFailedCallback)); } function onSucceededCallback(sender, args) { SP.UI.Status.addStatus("Info", "It worked!",true); } function onFailedCallback(sender, args) { SP.UI.Status.addStatus("Info", "It didn't work!",true); } Comments from Wordpress.com westerdaled - Feb 0, 2013
Thanks, I gather I can pass OnSucceedCallback as a delegate.