首页 \ 问答 \ 等待其他期货筹集的期货(Waiting for Futures raised by other Futures)

等待其他期货筹集的期货(Waiting for Futures raised by other Futures)

我正在使用Lawndart库来访问浏览器数据,并希望收集一组查询的结果。 这是我认为应该工作的:

  numberOfRecordsPerSection(callback) {
    var map = new Map();

    db_sections.keys().forEach((_key) {
      db_sections.getByKey(_key).then((Map _section) {
        int count = _section.length;
        map[_key] = count;
      });
    }).then(callback(map));
  }

但是,当调用回调时, map仍为空(它会正确填充,但稍后,在所有Futures完成后)。 我假设问题是由getByKey()调用创建的Futures不会被forEach()调用创建的Futures“捕获”。

如何更正我的代码以正确捕获结果?


I'm using the Lawndart library to access browser data, and want to collect the results of a set of queries. Here's what I thought should work:

  numberOfRecordsPerSection(callback) {
    var map = new Map();

    db_sections.keys().forEach((_key) {
      db_sections.getByKey(_key).then((Map _section) {
        int count = _section.length;
        map[_key] = count;
      });
    }).then(callback(map));
  }

However, when the callback is called, map is still empty (it gets populated correctly, but later, after all the Futures have completed). I assume the problem is that the Futures created by the getByKey() calls are not "captured by" the Futures created by the forEach() calls.

How can I correct my code to capture the result correctly?


原文:https://stackoverflow.com/questions/23969680
更新时间:2023-10-24 15:10

最满意答案

我的猜测是你会失去对回发的控制。 回发时动态添加的控件会丢失。 确定你重新创建了一个能够做同样事情的控件,但这并不意味着你能够捕捉到点击事件。 但是这个控件没有在回传之间传递的viewstate。

看到这篇文章如何去做这件事


My guess would be that you are losing the control on the postback. A dynamically added control gets lost on the postback. Sure you re-create a control that does the same thing, but that doesn't mean your going to be able to catch the click event. But the control doesn't have it's viewstate carried over between the postbacks.

See this article on how to go about doing this

相关问答

更多
  • Visual Basic Power Pack包含一个DataRepeater和一些包含一行的形状(椭圆形,矩形..)。 看到这个链接 。 它被称为“Visual Basic”Power Pack,但它可以在没有任何麻烦的情况下用于C#项目。 看看DataRepeater,它不仅可以帮助您将自定义控件作为项目填充到面板中,而且还包含需要在它们之间放置线条的内容。 The Visual Basic Power Pack contains a DataRepeater, and some shapes (ova ...
  • 假设2个控件包含相同的代码,则不会有任何性能差异。 它们之间的区别在于代码是如何编译的(Usercontrols直接编译到Web应用程序的dll中,并且服务器控件被编译到它们自己的dll中)以及编译时(通过它们自己或与Web应用程序一起)。 一旦编译完成,它们就像任何其他类一样。 Assuming the 2 controls contained identical code, there would not be any performance difference. The difference bet ...
  • 看起来你正在分组功能,所以我认为你不需要很多。 我所做的一些项目有大量资源的页面,我将这些资源转换为usercontrols,每次我显示它们时都会创建,否则如果它们相对轻量级,则更改其可见性将正常工作。 这一切都归结为你想要完成的事情。 It seems like you are grouping like functionality so I do not think you have to many. Some of the projects that I have done have had page ...
  • 有几个选项。 如果控件具有自然的层次结构(比如一个是另一个的父项),可以考虑将它们包装到用户控件中并利用RoutedEvents。 如果它们是兄弟控件,并且它们有一个自然父项,则将它们分组为一个父级用户控件,并为该控件处理交互创建一个视图模型。 如果控件在用户界面上完全独立的区域中,请考虑使用EventAggregator使控件触发并响应其他消息。 There are several options. If the controls have a natural hierarchy (such as one ...
  • 我需要做的是: 1)在用户控件中 - 创建一个事件委托(MouseEventHandler,而不是EventHandler) public event MouseEventHandler eventName; //this one is accessible from container form 2)在用户控制中 - 为组件控件的MouseDown事件编写一个方法,该方法将组件控件的事件连接到公开的事件 private void method_MouseDown(object sende ...
  • 我更喜欢选项A.动态加载控件并在回发中重新创建它们总是比在aspx-markup中切换控件的可见性要复杂得多且容易出错。 我必须承认,我不明白为什么你在小组和占位符之间有所区别。 主要区别仅在于Panel被渲染为DIV而PlaceHolder根本没有html。 如果你将UserControls全部放在页面中,你应该懒得加载你的UserControls,但只能看到单个UserControls。 这意味着: 在UserControl的Page_Load中不执行任何操作,但仅在控制器(页面)使其可见时才执行任何操 ...
  • 一种选择是将UserControlA实例传递给UserControlB的构造函数。 public partial class UserControlB: UserControl { UserControlA userControlA; public UserControlB(UserControlA ucA) { userControlA = ucA; InitializeComponent(); } private void bu ...
  • 我的猜测是你会失去对回发的控制。 回发时动态添加的控件会丢失。 确定你重新创建了一个能够做同样事情的控件,但这并不意味着你能够捕捉到点击事件。 但是这个控件没有在回传之间传递的viewstate。 看到这篇文章如何去做这件事 My guess would be that you are losing the control on the postback. A dynamically added control gets lost on the postback. Sure you re-create a ...
  • 您希望在UI的不同部分之间共享模型对象,以实现INotifyPropertyChanged接口。 使用BindingSource将控件与模型链接。 You want a model object shared between the different parts of your UI that implements the INotifyPropertyChanged interface. Use a BindingSource to link the controls with the model.
  • 虽然我知道你在询问如何在UserControl之间进行通信,但我建议答案是在视图模型之间进行通信。 使用delegate对象可以轻松实现这一点。 通常,您需要具有两个子视图模型共有的父视图模型。 我最近回答了类似的问题,所以我不会重复答案。 相反,我会请你看看StackOverflow上的viewmodels之间的传递参数的答案,它解释了代码示例的解决方案。 更新>>> 当我说你的孩子视图模型需要一个共同的父母时,我并不意味着与继承有关。 我只是说父项拥有每个子视图模型的变量实例...父实例化子视图模型。 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)