我想循环通过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) 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是否正确?
根据下图:

我想改进组件通信方法....我认为这种方式效率不高.
单击tabsetComponent以发出事件时,父控制器会捕获此事件,从而更改rootScope变量.在tableComponent中使用$ watch rootScope变量来触发http获取数据函数...
谁能有更好,更有效的方式来沟通兄弟组件?
我用过react-router,甚至尝试过<Redirect .. />,我无法重定向到/,主要问题是/是出于其他路线,所以我需要使用<Redirect from="*" to="" />,似乎无法正常工作.
然后我还需要防止/main重定向到/,我把它放在<Redirect .. >后面<Route component={MainView} path="main">
另一个要求,如何让localhost:3000来localhost: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)
有什么想法吗?
angularjs ×1
arrays ×1
components ×1
cors ×1
dictionary ×1
fetch ×1
fetch-api ×1
http ×1
immutable.js ×1
javascript ×1
preflight ×1
react-router ×1
reactjs ×1
routes ×1
watch ×1