小编Lor*_*ing的帖子

Angular 2从RxJs订阅返回数据

我有一个带有身份验证功能的服务 -

authenticate(username: string, password: string) {
        let ret;
        let packet = JSON.stringify({
            username: username,
            password: password
        });

        let headers = new Headers();
        headers.append('Content-Type', 'application/json');

        this.http.post('http://localhost:5000/api/authenticate/', packet, {
            headers: headers
        })
        .map(res => res.json())
        .subscribe(
            data => { 
                // put return data into ret
                ret = data.token;
            },
            err => console.log(err),
            () => {
                // this works!
                console.log(ret);
            }
        );

        // get's returned before I put data into it
        return ret;
    }
Run Code Online (Sandbox Code Playgroud)

因此,如果我调用authenticate函数console.log(authenticate('a', 'b'));,它会记录,undefined因为ret在subscribe函数将数据放入其中之前返回变量.如何从authenticate函数返回http响应数据?我之前从未对RxJS进行过任何反应式编程,而这正是角度2似乎正在使用的. …

asynchronous rxjs typescript angular

15
推荐指数
1
解决办法
2万
查看次数

Angular 2访问来自子组件的父路由队列

我有这个(主要的父母)组件 -

@RouteConfig([
    { path: '/', name: 'ProjectList', component: ProjectListComponent, useAsDefault: true },
    { path: '/new', name: 'ProjectNew', component: ProjectFormComponent },
    { path: '/:id', name: 'ProjectDetail', component: ProjectDetailComponent },
    { path: '/:id/issues/...', name: 'Issue', component: IssueMountComponent },
])
class ProjectMountComponent {
}
Run Code Online (Sandbox Code Playgroud)

然后我有第二个mount组件(主父的子代,下一个组件的父代)

@Component({
        template: `
        <div><router-outlet></router-outlet></div>
    `,
        directives: [RouterLink, RouterOutlet]
})
@RouteConfig([
        { path: "/", name: "IssueList", component: IssueListComponent, useAsDefault: true },
])
class IssueMountComponent {
    constructor(private _routeParams: RouteParams) {
    }
}
Run Code Online (Sandbox Code Playgroud)

在这里,我可以毫无问题地访问routeParams(:id).现在,这是我需要:id来自uri 的值的组件.

@Component({
        template: ` …
Run Code Online (Sandbox Code Playgroud)

javascript routing angular-routing angular

11
推荐指数
0
解决办法
7759
查看次数

将数据绑定到角度2路由组件

我现在有以下模板

<project-form [nextId]="projects.length" (newProject)="addProject($event)"></project-form>
<project-list [projects]="projects"></project-list>
Run Code Online (Sandbox Code Playgroud)

在ProjectAppComponent中.

class ProjectAppComponent {
    projects: Project[] = [
        { id: 0, title: "Build the issue tracker" },
        { id: 1, title: "Basecamp" },
    ]

    addProject(project: Project) {
        this.projects.push(project);
    } 
}
Run Code Online (Sandbox Code Playgroud)

ProjectAppComponent具有项目数组和将新项目推入其中的方法.我想创建子路由项目的形式和项目名单,所以我可以做的/projects/new,并/projects/show表现出任何形式或列表.我创建了这样的路线配置 -

@Component({
    template: `
        <div>
            <router-outlet></router-outlet>
        </div>
    `,
    directives: [ RouterOutlet ]
})
@RouteConfig([
    { path: '/list', name: 'ProjectList', component: ProjectListComponent, useAsDefault: true },
    { path: '/new', name: 'ProjectForm', component: ProjectFormComponent },
])
class ProjectAppComponent {
    projects: Project[] = …
Run Code Online (Sandbox Code Playgroud)

angular2-routing angular

8
推荐指数
1
解决办法
1242
查看次数

防止在ruby sinatra中固定会话

ruby中的大多数会话固定主题主要与rails相关.sinatra中是否存在任何会话固定漏洞?在rails中,我们主要建议在分配会话之前执行reset_session.我们如何防止sinatra中的会话固定?

ruby security session sinatra session-fixation

7
推荐指数
1
解决办法
1404
查看次数

Clojure core.async用于数据计算

我已经开始使用clojure core.async库了.我发现CSP,channel,go blocks的概念非常容易使用.但是,我不确定我是否正确使用它们.我有以下代码 -

(def x-ch (chan))
(def y-ch (chan))
(def w1-ch (chan))
(def w2-ch (chan))

; they all return matrices
(go (>! x-ch (Mat/* x (map #(/ 1.0 %) (max-fold x)))))
(go (>! y-ch (Mat/* y (map #(/ 1.0 %) (max-fold y)))))
(go (>! w1-ch (gen-matrix 200 300)))
(go (>! w2-ch (gen-matrix 300 100)))

(let [x1 (<!! (go (<! x-ch)))
        y1 (<!! (go (<! y-ch)))
        w1 (<!! (go (<! w1-ch)))
        w2 (<!! (go (<! w2-ch)))]

    ;; do stuff w/ …
Run Code Online (Sandbox Code Playgroud)

concurrency performance clojure core.async

4
推荐指数
2
解决办法
414
查看次数

无法在libgdx中加载渐进式jpeg图像

这是我的来源

package com.effect.bio;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Rectangle;

public class AppController implements ApplicationListener { 
    static final int WIDTH = 480;
    static final int HEIGHT = 320;

    private OrthographicCamera camera;
    private SpriteBatch batch;
    private Texture texture;
    private Sprite sprite;
    private Mesh mesh;
    private Rectangle glViewport;
    private float rotationSpeed;

    TiledMap map;
    TiledMapTileLayer layer;
    OrthogonalTiledMapRenderer renderer;

    @Override
    public void create() …
Run Code Online (Sandbox Code Playgroud)

java android opengl-es tmx libgdx

3
推荐指数
1
解决办法
2699
查看次数

迭代所有mongoid字段的最佳方法

说我有一个mongoid类

Class User
    include Mongoid::Document
    field :username, type: String
    field :age, type: Integer

    before_save :remove_whitespace

    def remove_whitespace
        self.username.strip!
        self.age.strip!
    end
end
Run Code Online (Sandbox Code Playgroud)

在方法中remove_whitespace; 有没有更好的方法迭代所有字段使用块和迭代器去除它们而不是单独键入每个字段(self.username.strip!)?我班上有大约15个领域,正在寻找一个优雅的解决方案.

ruby validation sanitization mongodb mongoid

1
推荐指数
1
解决办法
862
查看次数