没有获得更新模型。(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 in angular2. 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
2022-03-08 07:03

满意答案

尝试用以下代码替换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)

您可以通过在didFinishLaunchingWithOptions:执行以下操作来强制所需的方向didFinishLaunchingWithOptions:或在视图控制器的viewWillAppear: 。 [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO]; You can force the orientation you n...

如何让iPad旋转更流畅?(How to make iPad rotations more fluid?)

尝试用以下代码替换didRotateFromInterfaceOrientation调用: - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration { [UIView animateWithDuration:duration animations:^{ [self redefineLa...

如何让我的网站流畅?(how to make my website fluid?)

如果你想让你的网站流畅,只需使用百分比而不是像素。 .classname{ width: 80%; } if you want your website to be fluid just use percentage instead of pixels. .classname{ width: 80%; }

如何使一个ipad应用程序只有肖像?(How to make an ipad app only portrait?)

在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 ...

Apple iPad HIG?(Apple iPad HIG? [closed])

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?)

我找到了三种方法。我认为最后一种方式更好 1: 自动调整 例: UIImageView *myImageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImage.png"]]; myImageView.frame = self.view.bounds; myImageView.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizi...

ipad tabbar旋转(ipad tabbar rotation)

在info.plist中设置支持的接口方向 in the info.plist set Supported Interface Orientations

使应用程序在iPhone和iPad上运行(Make an application work on both iPhone and iPad)

为了使应用程序在iPhone和iPad上都能正常工作,需要按照以下步骤操作。 在创建项目之前,请在设备部分选择通用。 在应用程序中:didFinishLaunchingWithOptions:设置检查设备的条件。 如果设备是iPad,则加载iPad屏幕,如果设备是iPhone,则加载iPhone屏幕。 确保遵循MVC模式,以便在两个屏幕中轻松填充数据。 In order to make an application work in both iPhone & iPad then need to f...

在iPad上使用Selenium?(Using Selenium on iPad?)

要在Android设备浏览器中使用selenium代码,请尝试以下操作: 在您的计算机上安装Android SDK以访问Android Debug Bridge (adb)功能 使用"adb start-server"命令从cmd / Terminal启动adb服务器( 目标设备应已连接 ) 使用"chromedriver"命令( chromedriver可执行文件应该已经在您的系统Path )以相同的方式启动chromedriver服务器 你应该看到类似的东西: Starting ChromeD...

无法在iPad上禁用旋转功能(Cannot disabled rotation on iPad)

如果设备是通用的 ,它不会显示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.

相关文章

更多

论 NoSQL 的数据模型

本文内容是对《NoSQL Data Modeling Techniques》一文的简单概述,原文对No ...

Backbone.js的技巧和模式

本文由白牙根据Phillip Whisenhunt的《Backbone.js Tips And Pat ...

SSH中使用了模型驱动

我在使用了模型驱动,比如登陆操作,我写了一个POJO: public class Login { ...

Storm数据流模型的分析及讨论

转自:http://www.cnblogs.com/panfeng412/archive/2012/0 ...

DHI.MIKE.ZERO.v2007-ISO 1DVD(水利模型系统)

DHI.MIKE.ZERO.v2007-ISO 1DVD(水利模型系统) 包括以下模型系统: MIKE ...

开源项目列表

ElasticSearch Hessian Akka Socket.IO Node.js Kafka ...

Sentinel更新计划 Roadmap

Sentinel更新计划包括:注解支持、异步调用支持、热点参数限流、黑白名单功能、集群限流、与更多主流 ...

rails model的一点疑惑。。。。。

在rails中生成的model里面定义的属性都直接对应数据库字段,如何定义不需要对应数据库的属性呢? ...

DHI MIKE Zero 2012/DHI MIKE GIS/DHI MIKE URBAN 水利模型系统

DHI MIKE Zero 2012 SP3 Win32_64 2DVD 水利模型系统 DHI MIK ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本