callback

C#: passing parameters to callbacks

匆匆过客 提交于 2020-01-03 22:31:15
问题 I have a fairly generic class (Record) that I have added a callback handler to, so I can do something like the following. record.Save(AfterSaveMethod); Which also returns the identity number of the record created. The issue I have now is that I have this nested save routine in a loop, and I need to use/pass the i variable! for (int i; i < count ;i++) { record.Save(AfterSaveMethod2) //but I need to pass i through as well } What do I do here? A\ rewrite the save method and include it in this

C#: passing parameters to callbacks

十年热恋 提交于 2020-01-03 22:28:46
问题 I have a fairly generic class (Record) that I have added a callback handler to, so I can do something like the following. record.Save(AfterSaveMethod); Which also returns the identity number of the record created. The issue I have now is that I have this nested save routine in a loop, and I need to use/pass the i variable! for (int i; i < count ;i++) { record.Save(AfterSaveMethod2) //but I need to pass i through as well } What do I do here? A\ rewrite the save method and include it in this

How can I include a variable inside a callback function?

烂漫一生 提交于 2020-01-03 22:26:54
问题 I'm trying to get counts of array values greater than n . I'm using array_reduce() like so: $arr = range(1,10); echo array_reduce($arr, function ($a, $b) { return ($b > 5) ? ++$a : $a; }); This prints the number of elements in the array greater than the hard-coded 5 just fine. But how can I make 5 a variable like $n ? I've tried introducing a third argument like this: array_reduce($arr, function ($a, $b, $n) { return ($b > $n) ? ++$a : $a; }); // ^ ^ And even array_reduce($arr, function ($a,

js技巧-使用reduce实现更简洁的数组对象去重和数组扁平化

纵饮孤独 提交于 2020-01-03 21:39:32
Array.prototype.reduce()方法介绍: 感性认识reduce累加器: const arr = [1, 2, 3, 4]; const reducer = (accumulator, currentValue) => accumulator + currentValue; console.log(arr.reduce(reducer)); //10,即1 + 2 + 3 + 4。 console.log(arr.reduce(reducer, 6));//16,即6 + 1 + 2 + 3 + 4。 你可以通过打印reducer的两个参数,从而直观的感受到,第二个参数currentValue是当前的元素,而第一个参数accumulator总是返回每一次执行reducer函数的返回值,如此一次次累加起来。 reduce方法接收两个参数: reduce(callback,initialValue) callback(accumulator,currentValue, index,arr) : 执行于每个数组元素的函数; initialValue : 传给callback的初始值。 更详细的讲, callback 就是由你提供的 reducer函数 ,调用reduce()方法的 数组中的每一个元素都将执行你提供的reducer函数 ,最终汇总为 单个返回值 。

jQuery file upload plugin - fail callback not firing in IE < 10

会有一股神秘感。 提交于 2020-01-03 17:06:53
问题 I am using the https://github.com/blueimp/jQuery-File-Upload It uses XHR file uploads in modern browser and hidden iframe uploads in oldIEs (8,9). The server returns a 4xx status code (error/fail), when file validation failed. $('#fileupload').fileupload({ url: url, dataType: 'json', done: function (e, data) { console.log("done") }, fail: function (e, data) { console.log("fail") } }) However in oldIEs the done callback is called even when I send a 4xx status code. Is there a way to make it

Scrapy rules not working when process_request and callback parameter are set

人走茶凉 提交于 2020-01-03 15:54:52
问题 I have this rule for scrapy CrawlSpider rules = [ Rule(LinkExtractor( allow= '/topic/\d+/organize$', restrict_xpaths = '//div[@id= "zh-topic-organize-child-editor"]' ), process_request='request_tagPage', callback = "parse_tagPage", follow = True) ] request_tagePage() refers to a function to add cookie into requests and parse_tagPage() refers to a function to parse target pages. According to documentation, CrawlSpider should use request_tagPage to make requests and once responses are returned,

Scrapy rules not working when process_request and callback parameter are set

帅比萌擦擦* 提交于 2020-01-03 15:54:27
问题 I have this rule for scrapy CrawlSpider rules = [ Rule(LinkExtractor( allow= '/topic/\d+/organize$', restrict_xpaths = '//div[@id= "zh-topic-organize-child-editor"]' ), process_request='request_tagPage', callback = "parse_tagPage", follow = True) ] request_tagePage() refers to a function to add cookie into requests and parse_tagPage() refers to a function to parse target pages. According to documentation, CrawlSpider should use request_tagPage to make requests and once responses are returned,

NodeJS: invoking callback function inside a for loop

安稳与你 提交于 2020-01-03 13:11:08
问题 Basically, I am trying to call a function, where a loop is running inside of which many callback function are present (callback hell).. as below: for(var i=0;i<data.id.length;i++) { DAO.getUserById(data.id[i],function(err,resp1) { /* some other work based on resp1 */ DAO.getOtherData(resp1.username,resp1.userId,function(err,resp2) { /* similary some other work*/ }); }); } I have same pattern at several location in my app, and some time I faced issue with the callback, that for loop get over,

How to do Callbacks with Dynamic?

让人想犯罪 __ 提交于 2020-01-03 09:00:48
问题 I keep getting this error and not sure how to correct it Error 1 Cannot use 'Callback' as an argument to a dynamically dispatched operation because it is a method group. Did you intend to invoke the method? //... if (e.Status == LiveConnectSessionStatus.Connected) { client = new LiveConnectClient(e.Session); LiveOperationResult operationResult = await client.GetAsync("me"); try { dynamic meResult = operationResult.Result; var openId = meResult.id; var email = meResult.emails.preferred; /

How to make a callback after the view is completely rendered?

蓝咒 提交于 2020-01-03 07:59:06
问题 How to make a callback after the view is completely rendered ? I am trying to call a method which takes a screen-shot of parent view. If I write that code in onCreate() method, the app crashes due to null pointer (as no view is rendered). for now the temporary solution I have implemented is to make a delay of 1 second before calling that method. But, I am looking for a much more robust solution to this problem. any suggestions and help appreciated. thanks :) 回答1: Try this logic ... always