小编pro*_*ogx的帖子

如何对数组中的元素进行排序而不更改其他元素索引?

我有这个数组:

var arr = [5, 3, 2, 8, 1, 4];
Run Code Online (Sandbox Code Playgroud)

我正在尝试排序奇数值的元素,所以我想要这个

输出:

[1, 3, 2, 8, 5, 4]
Run Code Online (Sandbox Code Playgroud)

如你所见,偶数元素不会改变它们的位置.谁能告诉我我错过了什么?这是我的代码:

function myFunction(array) {

  var oddElements = array.reduce((arr, val, index) => {
    if (val % 2 !== 0){
      arr.push(val);
    }
    return arr.sort();
  }, []);

  return oddElements;
}
console.log(myFunction([5, 3, 2, 8, 1, 4]));
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用slice将元素添加到数组中,但我仍然坚持如何获取索引并将元素放入数组中.

javascript

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

sockjs 节点/信息?404(未找到)

我已经搜索了几个小时,但仍然找不到我要找的东西。基本上,在我的Angular 6 应用程序中运行 ng serve 时,我在控制台中收到此错误:

GET http://local.mywebsitesecure.com/sockjs-node/info?t=1540568455931 404 (Not Found)
Run Code Online (Sandbox Code Playgroud)

根据我的研究,解决方案可能只是更新

webpack.config.js

但是,我在我的项目中找不到 webpack.config.js。他们还说要做:

“ng弹出”

创建一个 webpack,但它似乎不起作用。

解决方案:我可以通过运行它来让它工作(它确实有效!):

ng serve --public-host= http://localhost:4200

但是我希望能够在我的应用程序的某个地方设置它,这样我就只能做

服务

有谁知道如何解决此问题并消除此错误(sockjs-node/info)。非常感谢!

webpack angular

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

拖动窗口

我对此做了一些研究,但仍然无法找到一个好的解决方案.我在ExtJS 4.1中编写了我的应用程序,当我在iPod上运行它时默认禁用拖动功能(这是我想要的),但如果我在ExtJS 6.2中编写相同的应用程序,所有窗口都可以拖动,这会导致可见性问题该应用程序.话虽如此,有没有人知道如何在使用平板电脑(iPod,iPad等)时禁用窗口拖动?我正在使用ExtJS 6.2

这是我的工作代码,适用于单个窗口,但我想要一个通用的解决方案,将阻止所有窗口被拖动.

       var win = Ext.create('Ext.Window', {
            title: "My Window",
            width: 500,
            modal: true,
            layout: 'fit',
            items: form,
            buttons: [{
                text: 'Close',
                handler: function() {
                    win.hide();
                }
            }]
        });

        win.show();

        if(Ext.os.deviceType === 'Tablet') {
            win.dd.disable();
        }
Run Code Online (Sandbox Code Playgroud)

javascript ios

10
推荐指数
2
解决办法
281
查看次数

在字段中输入 3 个字符后如何执行 API 调用?

我正在使用父组件和子组件。子组件具有输入字段,并将用户输入的值发送给父组件,如下所示:

<parent-component (sendInputValue)="getInputValue($event)"><parent-component>
Run Code Online (Sandbox Code Playgroud)

现在在父组件中我有这个:

getInputField(data){
 console.log(data); // this prints the data (Example: abc)
 //  then here I'm just executing the API call ONLY if data length is 3
  if(data.length === 3){
    this.myService.getDataFromService(data).subscribe(rs=>console.log(rs));
  }
}
Run Code Online (Sandbox Code Playgroud)

现在让我们说发生了这种情况:

  1. 用户输入:abc // API call gets execute that is good
  2. 现在,用户输入:abcd // 没有 API 调用被执行,很好
  3. 现在用户删除字母“d”,数据的新值将是“abc”我不想再次执行API调用,因为我们已经为“abc”执行了API调用
  4. 现在如果用户删除字母“c”,数据的新值现在是“ab”。此时,不需要 API 调用
  5. 现在,如果用户添加字母“c”,新值将是“abc”。此时,预期 API 调用。(这是工作)

那么,如果输入数据是 3 个字符,并且如果用户输入更多字符,则如何始终执行 API 调用,并且如果他删除字符并返回前 3 个字符,则不会发生任何事情,因为 API 已经发生了?非常感谢!

javascript rxjs typescript angular

10
推荐指数
2
解决办法
1852
查看次数

如何使用 date-fns-tz 检测时区缩写?

我想打印时区缩写,例如:IST、UTC、PST、MST、CST、EST 等...

我正在将代码从 momentJS 迁移到 date-fns 并遇到以下问题。当我使用 momentJS 时,一切都按预期工作。例如,下面的代码将打印“ IST

const timeZone = 'Asia/Calcutta';
moment.tz(new Date(), timeZone).format('z'); // IST
Run Code Online (Sandbox Code Playgroud)

使用 MomentJS 的演示

现在,我使用date-fns 的代码可以工作,但不能完全工作,因为它打印“印度标准时间”,而我只想打印IST

format(parisDate, 'zzzz', { timeZone: 'Asia/Calcutta', locale: enGB }); // India Standard Time
Run Code Online (Sandbox Code Playgroud)

谁能告诉我我错过了什么或做错了什么?这是我的代码的现场演示:date-fns DEMO

javascript timezone date-formatting momentjs date-fns

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

如何在PrimeNG中展开多个面板时修复损坏?

我正在使用多个面板,我添加了扩展/折叠它们的功能.我的问题是,当我展开它们时,我会看到所有面板中的一个丑陋的腐败文本.有谁知道如何解决这个问题?这是我的工作代码: PLUNKER

 <p-panel header="Panel 1" [toggleable]="true" [collapsed]="collapsed" [style]="{'margin-bottom':'20px'}">

 The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding.
His beloved son Michael has just come home from the war, but does not intend to become part of his father's business.
Through Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family,
kind and benevolent …
Run Code Online (Sandbox Code Playgroud)

javascript css typescript primeng angular

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

如何在Java中使用递归获取goldenRatio?

我正在研究这个简单的java递归问题,给出以下指示:

  • 计算黄金比例.

  • 给定两个数字a和b,其中a> b> 0,比率为b/a.

我已经完成了一些代码,但我仍然坚持让递归正常工作.这是我的代码:

public class MyTesting {

public static void main(String[] args) {
    System.out.println(ratio(8 , 4));
}

public static double ratio(int a, int b) {

    int goldelRatio = 0;
    if(a > b && b > 0){
        return goldelRatio = a / b;
    }

    return goldelRatio;
}

}
Run Code Online (Sandbox Code Playgroud)

java recursion

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

Laravel 中如何将数组值从一个方法传递到另一个方法?

我正在尝试将数组的值从 Laravel 中的一个方法传递到另一个方法。基本上我有一个名为orderingSubmission的方法,它从 Ajax POST 执行接收一个数组(该部分工作正常),但随后我尝试将数组值传递给另一个名为orderingSubmissionReceipt的方法,以便我最终可以在 order-summary 上呈现视图页。我正在使用会话,但它们似乎不起作用。谁能告诉我我缺少什么吗?

这是我的route.php

Route::get('/', function() { return redirect('home'); });
Route::get('home', 'HomeController@home');
Route::post('home', 'HomeController@activateCustomer');
Route::post('order-summary', 'HomeController@OrderingSubmission');
Route::get('order-summary', 'HomeController@orderingSubmissionReceipt');
Run Code Online (Sandbox Code Playgroud)

HomeController.php

public function orderingSubmission(Request $request)
{
    $allValues2 = $request->get('users'); // This code works fine. It gets the array
    Log::info('This is orderingSubmission.....: ' . print_r($allValues2, true));

   Session::set('allValues2',$allValues2);

}

public function orderingSubmissionReceipt()
{
    $allValues3 = Session::get('allValues2'); // This code is not getting the session value
    Log::info('This is orderingSubmissionReceipt.....: ' . print_r($allValues3, true));

    return view('order-summary', [ …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-5

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

如何添加垂直面板并将其用作Angular中的切换器?

点击"btn1"按钮时,我显示了这个sideBar.因此,我没有按钮,而是想要一个具有相同标题的垂直条.基本上我想完成这个:

预期结果

下面是我的代码到目前为止的样子.谁能指出我正确的方向?非常感谢提前.

DEMO

<button (click)="openTab()">btn1</button>
<p-sidebar [modal]="false" class="menuPanel" [(visible)]="opened" 
   position="left" [showCloseIcon]="true" autoZIndex="true" 
   baseZIndex="99999">
   This is the Title
</p-sidebar>
Run Code Online (Sandbox Code Playgroud)

css typescript primeng angular

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

如何使用Angular向API网关发出Get请求?

我正在尝试打以下AWS终端节点:

https://abcde12345hf.execute-api.us-east-2.amazonaws.com/dev/users
Run Code Online (Sandbox Code Playgroud)

返回:

[{
  "id": 1,
  "name": "Mike"
},{
  "id": 2,
  "name": "Brian"
}]
Run Code Online (Sandbox Code Playgroud)
  • 在我的Angular代码中,我使用AWS4库发送secretAccessKeyaccessKeyIdsessionToken来验证用户身份,但是出现以下错误:

core.js:12501错误错误:未捕获(承诺):错误:请求失败,状态码为403错误:请求失败,状态码为403

  • 有谁知道如何在Angular中正确使用AWS4,因此我可以进行此简单的GET调用?还是有人知道使用这些密钥和令牌进行身份验证的另一种方法吗?在此先多谢!

这就是我获取密钥和令牌的方式(这一部分效果很好)

AWS.config.region = 'us-east-2';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
    IdentityPoolId: 'us-east-2:ehkjthf-sf23-12ds-xxxxxxxxx',
    Logins: {
        'cognito-idp.us-east-2.amazonaws.com/us-east-2_Raxxxx': this.id_token
    }
});

console.log(AWS.config.credentials);
Run Code Online (Sandbox Code Playgroud)

现在,这就是我使用这些键和令牌进行GET调用的方式。

(AWS.config.credentials as AWS.Credentials).get(function(error: AWSError){
  if(error){
    console.log('Error ', error);
  }else{
  let request = {
    host: 'https://abcde12345hf.execute-api.us-east-2.amazonaws.com/dev/users',
    method: 'GET',
    url:  'https://abcde12345hf.execute-api.us-east-2.amazonaws.com/dev/users',
    path: '/users',
    headers: {
      "Content-Type":"application/json"
    },
  }

  let signedRequest = aws4.sign(request,
    { …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-api-gateway angular

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