假设我们有以下javascript对象:
ahash = {"one": [1,2,3], "two": [4,5,6]}
Run Code Online (Sandbox Code Playgroud)
有没有函数,它返回对象中第一个键的值?(我不知道密钥名称,我只想获得第一把钥匙的价值).
我希望有一个像这样的日期倒计时:
http://codepen.io/garethdweaver/pen/eNpWBb
但是在角度2中,我发现这个plunkr每500毫秒增加一个数字:
https://plnkr.co/edit/pVMEbbGSzMwSBS4XEXJI?p=preview
这是代码:
import {Component,Input} from 'angular2/core';
import {Observable} from 'rxjs/Rx';
@Component({
selector: 'my-app',
template: `
<div>
{{message}}
</div>
`
})
export class AppComponent {
constructor() {
Observable.interval(1000)
.map((x) => x+1)
.subscribe((x) => {
this.message = x;
}):
}
}
Run Code Online (Sandbox Code Playgroud)
但我希望约会一秒钟,直到达到0.
我正在尝试使用哈希位置策略创建应用程序,但它不会将哈希添加到URL.例如,当我点击与{path:'/ polls',name:'Polls',component:PollsComponent}关联的按钮时,它会使用此url加载页面:localhost:3000/polls.
我需要更改以获取哈希位置策略?如果我想使用哈希位置策略,为什么必须设置默认基本URL?
这是app.component.ts中的路由,其中定义了所有路由:
import {Component} from 'angular2/core'
import {HTTP_PROVIDERS, Http} from 'angular2/http';
import 'rxjs/Rx'; // load the full rxjs
import {ROUTER_PROVIDERS, RouteConfig , ROUTER_DIRECTIVES} from 'angular2/router';
import { ResultsComponent } from './results/results.component'
import { VotingCardsComponent } from './votingcards/votingcards.component'
import { DashBoardComponent } from './dash/dash.component'
import { PollsComponent } from './pollslist/pollslist.component'
@Component({
selector: 'my-app',
templateUrl: 'app/app.component.html',
directives: [ROUTER_DIRECTIVES, ResultsComponent, VotingCardsComponent, DashBoardComponent],
providers: [HTTP_PROVIDERS,
ROUTER_PROVIDERS]
})
@RouteConfig([
{ path: '/vote', name: 'VotePage', component: VotingCardsComponent },
{ path: '/votepoll/:id', name: 'VotePoll', component: …Run Code Online (Sandbox Code Playgroud) 我创建了一个 angular 2 应用程序。在我的 app.component 我有这个
<header-component><header-component>
<router-outlet></router-??outlet>
Run Code Online (Sandbox Code Playgroud)
与路由器:
const appRoutes: Routes = [
{ path: 'profesionals', component: CrearEditarProfesionalsComponent },
{ path: 'home', component: HomeComponent },
{ path: 'login', component: LoginComponent },
{ path: '', component: HomeComponent }
];
Run Code Online (Sandbox Code Playgroud)
当我导航到登录时,我想摆脱
<header-component>
Run Code Online (Sandbox Code Playgroud)
但是对于用户登录时的所有其他页面,我只想按原样显示布局。我是否必须将 ng-if 与服务一起使用才能存档?最好的方法是什么?
我在nodejs中有一个带有jwt授权的应用程序,当我从posman发送get时,找到了身份验证标头,但是当我从浏览器发送它时,授权标头丢失了。这是节点代码,我试图在 verifyToken 方法中获取授权标头,但不存在:
'use strict';
var SwaggerExpress = require('swagger-express-mw');
var app = require('express')();
module.exports = app; // for testing
var _ = require('lodash');
var jwt = require('jsonwebtoken'); // used to create, sign, and verify tokens
var config = {
appRoot: __dirname // required config
};
app.set('superSecret', config.secret); // secret variable
// bootstrap database connection and save it in express context
app.set("models", require("./api/model"));
var a = app.get("models").Role;
var repositoryFactory = require("./api/repository/RepositoryFactory").init(app);
var verifyToken = function (req, res, next) {
// verify …Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的对象:
state: {
"1": {
"show": false,
"description": "one",
"children": {
"1": { "show": false, "description": "one" },
"2": { "show": false, "description": "one" }
}
},
"2": {
"show": false,
"description": "one",
"children": {
"1": { "show": false, "description": "one" },
"2": { "show": false, "description": "one" }
}
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个 for 循环,可以将子项“show”属性更改为相反的布尔值。所以我尝试用这个来更新值,但没有成功。
for (var childKey in state[appClassId].children) {
newState = {
...state,
[appClassId]: {
children: {
[childKey]: { ...state[appClassId].children[childKey], show: !state[appClassId].children[childKey].show}
}
}
Run Code Online (Sandbox Code Playgroud)
“appClassId”变量是我从操作中获取的变量。
如何更新子属性中的每个键,例如 state.1.children.1.show
我有一个像这样的数组:
var oldArray = [{'value': '1', 'label': 'a'}, {'value': '2', 'label': 'b'}]
Run Code Online (Sandbox Code Playgroud)
我想要的是使用传播运算符在该数组的开头添加一个新对象:
顺便说一句,这有效:
var oldArray = [{'value': '1', 'label': 'a'}, {'value': '2', 'label': 'b'}]
var newObj = {'value': 'all', 'label': 'all'}
var result = [newObj, ...oldArray]
Run Code Online (Sandbox Code Playgroud)
但是会生成如下所示的键“ newObj”:
var oldArray = [newObj : {'value': 'all', 'label': 'all'}, 0: {'value': '1', 'label': 'a'}, 1:{'value': '2', 'label': 'b'}]
Run Code Online (Sandbox Code Playgroud)
我希望像这样,自动生成密钥:
var result = [{'value': 'all', 'label': 'all'}, ...oldArray]
Run Code Online (Sandbox Code Playgroud)
并想象结果是这样的:
var oldArray = [newObj : {0: 'all', 'label': 'all'}, 1: {'value': '1', 'label': …Run Code Online (Sandbox Code Playgroud) 我在reducer中有一个状态如下:
// The current source/selection
const selection = {
timespan: "-3660",
customTimespan: false,
pathIds: [''],
source: undefined,
direction: 0,
appClassIds: []
};
Run Code Online (Sandbox Code Playgroud)
我现在想要的是更新多个属性(timespan和customTimeSpan),类似这样(但这不起作用):
{ ...state,
{
timespan: action.timespan.value,
customTimespan: action.timespan.value
}
};
Run Code Online (Sandbox Code Playgroud)
如何更新状态的多个属性?
我是实体框架的新手,我正在使用Nhibernate.在Nhibernate更新对象时,传递id不是必需的,你只需传递实体,Nhibernate就自己匹配id并更新实体.在EF我正在使用这个aprouch:
protected virtual bool UpdateEntity(TEntity entity, int id)
{
using (var ctx = new GenericContext())
{
var list = ctx.Set<TEntity>().ToList();
ctx.Entry<TEntity>(ctx.Set<TEntity> ().Find(id)).CurrentValues.SetValues(entity);
return ctx.SaveChanges() > 0;
}
}
Run Code Online (Sandbox Code Playgroud)
这需要id来更新实体.这是最好的aprouch吗?有一些方法来更新实体只是在没有找到它的情况下传递实体?
我在Angular组件中启动一个间隔,但即使在我更改路径后它也会继续发出请求.我该如何停止间隔?
//returns an observable
getAllPolls() {
return Observable.interval(2000).switchMap(() => this._http.get('https://xq4kftam4k.execute-api.us-east-1.amazonaws.com/test/polls2'))
.map((res: Response) => res.json())
}
Run Code Online (Sandbox Code Playgroud) javascript ×7
angular ×4
react-redux ×3
reactjs ×3
redux ×2
arrays ×1
c# ×1
express ×1
http ×1
node.js ×1
rxjs ×1
typescript ×1