小编Sev*_*Lee的帖子

如何像forEach一样遍历不可变列表?

我想循环通过Immutable List,我曾经List.map这样做,它可以工作,但不好.有更好的方法吗?因为我只检查数组中的每个元素,如果元素符合我的规则,我会做一些事情,就像Array.forEach,我不想返回任何类似的东西Array.map.

例如,现在是我的工作:

let currentTheme = '';
let selectLayout = 'Layout1';
let layouts = List([{
  name: 'Layout1',
  currentTheme: 'theme1'
},{
  name: 'Layout2',
  currentTheme: 'theme2'
}])


layouts.map((layout) => {
  if(layout.get('name') === selectLayout){
     currentTheme = layout.get('currentTheme');
  }
});
Run Code Online (Sandbox Code Playgroud)

arrays dictionary immutable.js

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

获取API:无法在Chrome上的请求标头上添加授权

Chrome版本:57.0.2987

实际上,在较旧的Chrome版本中我也有这个问题.我Authorization在Request Header上添加了访问令牌,

fetch('https://example.com/endpoint', {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer ' + accesstoken
  }  
})
Run Code Online (Sandbox Code Playgroud)

我总是在Chrome中Access-Control-Allow-Headers:authorization使用响应标题除此之外,我的提取始终是请求方法:选项(不显示GET),然后Status Code在Chrome中为200 OK

但是如果我在Firefox(版本52.0.1)中运行相同的获取代码,一切都很好.我可以添加Authorization请求标题正确.它不会显示Access-Control-Allow-Headers:authorization响应头在Firefox.它将显示Authorization: Bearer accesstoken在Request标头上.

服务器端已经为我的请求标头处理了CORS ..

这是Chrome错误或我的代码错误?我应该怎么做才能让Authorization请求头在Chrome是否正确?

下面的图片是细节Chrome的开发工具: 下面的图片是Chrome开发工具中的详细网络:

下面的图片是细节Firefox的开发工具: 在此输入图像描述

http fetch cors preflight fetch-api

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

在Angular 1.x中传达组件或指令的有效方法

根据下图:

在此输入图像描述

我想改进组件通信方法....我认为这种方式效率不高.

单击tabsetComponent以发出事件时,父控制器会捕获此事件,从而更改rootScope变量.在tableComponent中使用$ watch rootScope变量来触发http获取数据函数...

谁能有更好,更有效的方式来沟通兄弟组件?

components watch angularjs angularjs-directive

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

React-router自动将任何路由重定向到root"/",除了"/ main"

我用过react-router,甚至尝试过<Redirect .. />,我无法重定向到/,主要问题是/是出于其他路线,所以我需要使用<Redirect from="*" to="" />,似乎无法正常工作.

然后我还需要防止/main重定向到/,我把它放在<Redirect .. >后面<Route component={MainView} path="main">

另一个要求,如何让localhost:3000localhost:3000/使用AppIndexIndexRoute

请检查以下代码:

import MainView from 'components/MainView';
import ThemeIndex from 'components/ThemeIndex';
import AppIndex from 'components/ThemeIndex';
import Shop from 'components/Shop';
import App from 'components/App';

export default (
    <Route component={App} path="/">
      <IndexRoute component={AppIndex}></IndexRoute>
      <Route component={MainView} path="main">
        <IndexRoute component={ThemeIndex}></IndexRoute>
      </Route>
      <Redirect from="*" to="" />
    </Route>
);
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?

javascript routes reactjs react-router

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