just read this article file:///E:/download/Execute%20javascript%20code%20from%20ASP.NET%20Core%20back-end%20using%20NodeServices%20good.htm
var _ = require('lodash');module.exports = {sortBy: function (callback, data, option) {var result = _.sortBy(data, [option]);
callback(null, result);
}
};
[Produces("application/json")]
[Route("api/Users")]publicclassUsersController : Controller
{
[HttpGet("GetSortedUsers")]publicasync Task<IActionResult> SortedUsers([FromServices] INodeServices nodeServices, string sortBy){var data = new User[]
{new User {Name = "fred", Age = 48},new User {Name = "barney", Age = 36},new User {Name = "fred", Age = 40},new User {Name = "barney", Age = 34}
};var sortedUsers = await nodeServices.InvokeExportAsync<User[]>("./Node/lodash", "sortBy", data, sortBy);return Ok(sortedUsers);
}
}
specially see this line var sortedUsers = await nodeServices.InvokeExportAsync<User[]>("./Node/lodash", "sortBy", data, sortBy);
this area is not clear ("./Node/lodash", "sortBy", data, sortBy);
first one is the js file path? second one is function name ? what is 3rd and 4th argument?
module.exports = function (callback, first, second) { var result = first + second; callback(/* error */ null, result); }; var result = await nodeServices.InvokeAsync<int>("./addNumbers", 1, 2);
see this ("./addNumbers", 1, 2);
what is the name of js function ?
what this line callback(/* error */ null, result); will do?
please help me to understand how the above code will work. thanks