没有获得更新模型。(not getting updates on model. socket.io with sails.js)
我使用选项
--no-linker --no-front end
创建了一个sails应用程序。 应用程序的前端以angular2
编写。 请求获取和发布,似乎工作正常。当我向路由发送获取请求(订阅)时,我无法获得有关正在创建,更新或销毁的模型的任何更新。
我也创造了一个特别的行动,所以我可以自己做事情,但仍然没有运气。
在路由上执行的更新使用套接字进行。 我不知道这里错在哪里。 在下面找到我的代码
import { Injectable, OnInit, EventEmitter } from '@angular/core' import { Subject } from 'rxjs/Subject'; import { Donor } from './donor.interface'; import * as socketIO from 'socket.io-client' import * as sailsIO from 'sails.io' const url = 'http://localhost:1337' const io = sailsIO(socketIO) io.sails.reconnection = true; io.sails.url = url; io.socket.on('connect', function () { console.log("connected to server") io.socket.get('/donor', function (data, jwres) { console.log("i subscribed", data, jwres) }) io.socket.get('/donor/hello', function (data, jwres) { console.log("i subscribed with hello", data, jwres) }) io.socket.on('donor', function (data) { console.log("new donor was created", data) }); }); io.socket.on('disconnect', function () { console.log('Lost connection to server'); });
DonorController.js
module.exports = { hello: function (req, res) { if (req.isSocket) { Donor.watch(req.socket) console.log("new subscriber found") } else { console.log("not a socket req") } return res.ok(); } };
I have a sails app created using the options
--no-linker --no-front end
. The front end of the application is written inangular2
. Making request get and post, seems to work fine.When i send a get request to the route (to subscribe), i don't get any updates on model being created, updated or destroyed.
I also created a special action, so i could do thing myself, but still with no luck.
The updates performed on the route are made using socket. I don't know where am wrong here. Find my code below
import { Injectable, OnInit, EventEmitter } from '@angular/core' import { Subject } from 'rxjs/Subject'; import { Donor } from './donor.interface'; import * as socketIO from 'socket.io-client' import * as sailsIO from 'sails.io' const url = 'http://localhost:1337' const io = sailsIO(socketIO) io.sails.reconnection = true; io.sails.url = url; io.socket.on('connect', function () { console.log("connected to server") io.socket.get('/donor', function (data, jwres) { console.log("i subscribed", data, jwres) }) io.socket.get('/donor/hello', function (data, jwres) { console.log("i subscribed with hello", data, jwres) }) io.socket.on('donor', function (data) { console.log("new donor was created", data) }); }); io.socket.on('disconnect', function () { console.log('Lost connection to server'); });
DonorController.js
module.exports = { hello: function (req, res) { if (req.isSocket) { Donor.watch(req.socket) console.log("new subscriber found") } else { console.log("not a socket req") } return res.ok(); } };
原文:https://stackoverflow.com/questions/40973346
最满意答案
尝试用以下代码替换
didRotateFromInterfaceOrientation
调用:- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration { [UIView animateWithDuration:duration animations:^{ [self redefineLayout]; }]; }
Try replacing your
didRotateFromInterfaceOrientation
call with this:- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration { [UIView animateWithDuration:duration animations:^{ [self redefineLayout]; }]; }
相关问答
更多-
iPad启动方向(iPad startup orientation)[2023-10-04]
您可以通过在didFinishLaunchingWithOptions:执行以下操作来强制所需的方向didFinishLaunchingWithOptions:或在视图控制器的viewWillAppear: 。 [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO]; You can force the orientation you need b ... -
尝试用以下代码替换didRotateFromInterfaceOrientation调用: - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration { [UIView animateWithDuration:duration animations:^{ [self redefineLayout] ...
-
如何让我的网站流畅?(how to make my website fluid?)[2023-03-18]
如果你想让你的网站流畅,只需使用百分比而不是像素。 .classname{ width: 80%; } if you want your website to be fluid just use percentage instead of pixels. .classname{ width: 80%; } -
在xcode中选择你的项目。 转到目标 - >常规,向下滚动,您可以选择只作为肖像的方向。 您还可以更改info.plist文件以选择适当的方向以支持界面方向(iPad) In xcode select your project. Go to Targets -> General, scroll down and you can select the Orientation as portrait only. You can also make change to info.plist file to se ...
-
Apple iPad HIG?(Apple iPad HIG? [closed])[2021-12-19]
HIG从未明确声明您的应用程序必须支持轮换。 对于许多应用来说,旋转是没有意义的,这是允许的。 The HIG never explicitly states that your application must support rotation. For many applications, it doesn't make sense to rotate, and that's allowed. -
处理iphone / ipad图像旋转的正确方法是什么?(What is the proper way to handle image rotations for iphone/ipad?)[2022-11-24]
我找到了三种方法。我认为最后一种方式更好 1: 自动调整 例: UIImageView *myImageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImage.png"]]; myImageView.frame = self.view.bounds; myImageView.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFle ... -
ipad tabbar旋转(ipad tabbar rotation)[2023-04-28]
在info.plist中设置支持的接口方向 in the info.plist set Supported Interface Orientations -
为了使应用程序在iPhone和iPad上都能正常工作,需要按照以下步骤操作。 在创建项目之前,请在设备部分选择通用。 在应用程序中:didFinishLaunchingWithOptions:设置检查设备的条件。 如果设备是iPad,则加载iPad屏幕,如果设备是iPhone,则加载iPhone屏幕。 确保遵循MVC模式,以便在两个屏幕中轻松填充数据。 In order to make an application work in both iPhone & iPad then need to follow ...
-
在iPad上使用Selenium?(Using Selenium on iPad?)[2020-05-09]
要在Android设备浏览器中使用selenium代码,请尝试以下操作: 在您的计算机上安装Android SDK以访问Android Debug Bridge (adb)功能 使用"adb start-server"命令从cmd / Terminal启动adb服务器( 目标设备应已连接 ) 使用"chromedriver"命令( chromedriver可执行文件应该已经在您的系统Path )以相同的方式启动chromedriver服务器 你应该看到类似的东西: Starting ChromeDriver ... -
无法在iPad上禁用旋转功能(Cannot disabled rotation on iPad)[2022-06-01]
如果设备是通用的 ,它不会显示iPhone和iPad的方向 。 您应该选择Devices is iPad ,并设置Device Orientation 。 If the Devices is Universal, it doesn't show the Orientation for both iPhone and iPad. You should choose Devices is iPad, and set up Device Orientation.