- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这两个函数有什么区别吗?
我最近在 Controller 中使用 Promise.all
时发现了一个问题。 View 将在 Promise.all
完成之前渲染,并且我会在 View 内得到空变量。
因此,如果我使用一个 m.request
来访问单个 api,那么 View 将等待它完成。如果我使用许多包裹在 Promise.all
中的 m.request
那么它不会等待!我做错了什么吗?
这是正确的行为吗? m.sync
的行为是否会有所不同,它似乎与 Promise.all
具有相同的签名?
谢谢。
编辑
具有相关位的代码
// Does two requests and wraps them in Promise.all
Table.show = (id, load) => {
var header = m.request({
method: "GET",
url: cfg.apiurl(`/tables/${id}`),
});
var body = m.request({
method: "POST",
url: cfg.apiurl(`/tables/${id}`),
data: {
data: load
}
});
return Promise.all([header, body]);
};
// The component
var ShowTable = {
controller, view
};
// Controller function
function controller() {
this.header = m.prop({});
this.records = m.prop([]);
this.pages = m.prop(0);
var load = {
filter: {},
paging: {
number: 1,
size: 10
}
};
var showTable = () => {
Table.show(m.route.param("id"), load).then((res) => {
this.header(res[0].data);
this.records(res[1].data);
this.pages(res[1].meta.pages);
}, (res) => {
popa();
});
};
showTable();
}
// View function
function view(vm) {
return m("div", [
m("p", vm.header()),
m("p", vm.records()),
m("p", vm.pages()),
]);
}
编辑2
是的,m.sync
有效。但 Promise.all
却没有。
最佳答案
快速浏览一下文档,我找到了 this page 。重绘仅针对 mithril 的内置函数完成,Promise.all
是原生 JavaScript 函数,因此不会自动重绘。您应该在 showTable
函数中使用 m.sync
或 m.startComputation/m.endComputation
。您甚至可以直接返回 [header, body]
而无需 Promise.all/m.sync
,它们都是 Promise 和 mithril props,因此您可以使用/将它们分配给您的 viewmodel当它们的值被填充时,它应该触发 View 中的重绘。
不管怎样,如果还是不行,别浪费时间了,直接把m.redraw()
放在Promise.all
的then中即可。
关于javascript - Promise.all 与 m.sync,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33748937/
是否可以使用 MS Sync Framework 同步不同数据库中的不同表(具有完全不同的结构),假设其中一个表具有主键,另一个具有唯一索引,其值与第一个表的 PK 一致(但不能晋级PK)?列名也可以
我正在开发一个使用 Twilio Sync 作为数据库的应用程序。我确实订阅了很多事件,例如 itemAdded、itemUpdated、itemRemoved,以使用 Sync Javascript
我们计划使用 ADO.NET 的同步服务将商店与总部同步,有人建议我通过 进行同步。 WCF 代理 . 通过 WCF 代理同步是否意味着我将能够 通过 http 同步 ?如果没有,是否可以使用同步服务
在 Sync Framework 2.1 中,批处理似乎得到了内置支持,因此在某些提供程序中,我们可以只提及批处理大小和假脱机文件位置(以及一些其他属性),批处理将得到处理。开发人员不必编写自己的批处
'sync' 事件和 Backbone.sync 有什么区别? ...它们分别是什么? 最佳答案 虽然两者都与向服务器同步数据的任务有关,但两者之间没有任何联系。 Backbone.sync实现您的
在 Go 中,我们可以使用: type Data struct { lock *sync.Mutex } 或 type Data struct { lock sync.Mutex
我们在各种客户项目中使用 Microsoft Sync Framework 2.1 进行文件和数据库同步。扩展支持将于 2021 年结束。 所以我的问题是: 微软的同步框架策略是什么?它会是开源的,所
我在这个站点和其他站点上看到了一些帖子,指出问题通常是由将表添加到客户端的 SyncAgent 配置或提供者端的 SyncAdapter 的顺序引起的。我相信我在这两个地方都正确地对表格进行了排序(我
Using an Asynchronous Controller in ASP.NET MVC 的使用 BeginMethod/EndMethod 模式部分指的是 Sync() 方法。它没有链接,我无
这是代码: type someThing struct { sync.Mutex cv *sync.Cond num int } func NewSometh
异步地做多项工作(排序向量,主要是函数计算(计算是计算或内存限制,目前,我可以用以下方式编写这些操作: 使用 Threads.@spawn _f1 = Threads.@spawn f1(x) _f2
我想使用 Rust 和 once_cell实现一些静态常量结构实例,一个静态常量向量包含这些静态结构实例。 示例代码如下: use once_cell::sync::Lazy; pub struct
我想使用 Rust 和 once_cell实现一些静态常量结构实例,一个静态常量向量包含这些静态结构实例。 示例代码如下: use once_cell::sync::Lazy; pub struct
看了sync.Pool的设计,发现是两个逻辑,为什么要用localPool来解决锁竞争。我们可以只使用 chan 来实现一个。 使用 channel 比 sync.pool 快 4 倍! pool除了
我有一个编码为在模糊时运行 save_notes 函数的文本区域。当 save_notes 调用时,我在控制台中得到以下内容: TypeError: Cannot read property 'syn
如果 Waitgroups 和 Mutex 总是需要通过引用传递,我们不能把它做成引用类型(禁止使用它们作为值传递)吗?我的意思是有没有我们需要使用它们按值传递的用例? 最佳答案 当您将任何参数作为值
背景:我正在尝试创建一个完全异步 Node js 演示的小测试。然后我可以看到一个好的样本是什么样的,以便清理我完成的其他一些项目。 这是我的代码 //https://medium.com/@tkss
http://msdn.microsoft.com/en-us/library/dd918848.aspx “了解作用域是表和筛选器的组合很重要。例如,您可以定义一个名为 sales-WA 的筛选作用
我尝试同步我的 Visual Studio 代码设置/扩展。我手动执行的许多同步步骤。 然后我发现了这两个工具 https://code.visualstudio.com/docs/editor/se
我正在尝试移植一个扩展,但我的 JS 非常生疏。 https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Chro
我是一名优秀的程序员,十分优秀!