我试图使用Array.prototype切片对象,但是它返回一个空数组,除了传递参数之外是否有任何方法来切片对象,或者只是我的代码有错误?谢谢!!
var my_object = {
0: 'zero',
1: 'one',
2: 'two',
3: 'three',
4: 'four'
};
var sliced = Array.prototype.slice.call(my_object, 4);
console.log(sliced);
Run Code Online (Sandbox Code Playgroud) 我有这个对象数组,我需要修改它以使渲染更容易。
const items = [
{
tab: 'Results',
section: '2017',
title: 'Full year Results',
description: 'Something here',
},
{
tab: 'Results',
section: '2017',
title: 'Half year Results',
description: 'Something here',
},
{
tab: 'Reports',
section: 'Marketing',
title: 'First Report',
description: 'Something here',
},
...
];
Run Code Online (Sandbox Code Playgroud)
我正在尝试修改它,按特定键对它们进行分组。这个想法是有这个输出。如您所见,键的名称可能与项目中的实际名称不同。我认为这与以前的帖子有点不同。
const output = [
{
tab: 'Results',
sections: [
{
section: '2017',
items: [ { 'item that belongs here' }, { ... } ],
},
},
{
tab: 'Reports',
sections: [
{
section: 'Marketing', …Run Code Online (Sandbox Code Playgroud) 我正在使用odata api,当我使用邮递员做GET请求时,工作完美,我得到的回应正如我所期待的那样.

但是当我使用来自我的React应用程序的获取请求时,请求会抛出401,使用与之前在Postman中使用的相同的标头.它说的Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 401.
有关如何解决此请求的任何想法?谢谢!
fetch('https://api4.successfactors.com/odata/v2/', {
method: 'GET',
headers: {
authorization: `Basic ${auth}`, //auth is the encoded base64 username:password
},
})
.then(response => response.json())
.then((response) => {
console.log('in response: ', response);
})
.catch((error) => {
console.log('in fetchJobs error: ', error);
});Run Code Online (Sandbox Code Playgroud)