osmiumbin
osmiumbin

Reputation: 339

Passing complex types from SignalR hub to javascript

From the hub i need to call a function on the client that is expecting an undefined number of object-type parameters like this

{name: 'John', age: 20}, {key: 'Smith', id: 5, ...} ...etc

but i obviously can't write the arguments like that on the server side. I could just send all the data as a single string value and parse it on the client but i feel there has to be a better way to achieve this.

Thanks!

Upvotes: 0

Views: 808

Answers (1)

Robert Levy
Robert Levy

Reputation: 29073

Send an array of objects to a function on the client. Have this function then split that array up into parameters to pass into your existing function by using 'apply':

function wrapperFunctionToCallFromServer(arrayOfObjectParameters) {
  actualFunctionYouWantToCall.apply(this, arrayOfObjectParameters);
}

Upvotes: 1

Related Questions