简体   繁体   English

当控制器工作时,sailsjs更新视图

[英]sailsjs update view while controller is working

Firstly I'm totally new to SailsJs. 首先,我对SailsJs完全陌生。 I've been asked to learn it and make some demo app. 我被要求学习它并制作一些演示应用程序。 One of them is simply a loop in a controller and output each results in the view while the controller is still working. 其中之一就是控制器中的一个循环,并在控制器仍在工作时在视图中输出每个结果。 However it doesn't seem simple as that. 但是,这似乎并不简单。 After some research I found the async lib but I can't use it since we're using an older version of node and dependencies doesn't met and I can't use any other node version for some reason. 经过一番研究后,我发现了异步库,但是由于我们使用的是较旧版本的节点,并且无法满足依赖项,并且由于某种原因,我无法使用任何其他节点版本,因此无法使用它。 So is there any way to do this without using any other lib? 因此,有没有其他任何方法可以执行此操作? Maybe I should use sockets for this? 也许我应该为此使用套接字?

I would ask why you think you need the async library for this? 我想问一下,为什么您认为需要异步库呢? I have written out a test controller below. 我在下面写了一个测试控制器。 In order to do what you want to do, you just have to use the express methods required and not use the custom responses that sails.js has built in. 为了执行您想做的事情,您只需要使用所需的express方法,而不使用sails.js内置的自定义响应。

TestController.js
module.exports.test = function(req,res,next){

 response.status(200).set('Content-Type', 'text/plain');;

 for(var i = 0; i < 10, i++){

 response.write(i);

 }
 return response.end();

};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM