首页 \ 问答 \ 没有获得更新模型。(not getting updates on model. socket.io with sails.js)

没有获得更新模型。(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];
    }];
}

相关问答

更多
  • 您可以通过在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] ...
  • 如果你想让你的网站流畅,只需使用百分比而不是像素。 .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 ...
  • 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.
  • 我找到了三种方法。我认为最后一种方式更好 1: 自动调整 例: UIImageView *myImageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImage.png"]]; myImageView.frame = self.view.bounds; myImageView.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFle ...
  • 在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 ...
  • 要在Android设备浏览器中使用selenium代码,请尝试以下操作: 在您的计算机上安装Android SDK以访问Android Debug Bridge (adb)功能 使用"adb start-server"命令从cmd / Terminal启动adb服务器( 目标设备应已连接 ) 使用"chromedriver"命令( chromedriver可执行文件应该已经在您的系统Path )以相同的方式启动chromedriver服务器 你应该看到类似的东西: Starting ChromeDriver ...
  • 如果设备是通用的 ,它不会显示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.

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)