小编Sau*_*ari的帖子

如果writable属性默认为false,那么JS对象如何可变

我试图了解JS中的Object突变是如何工作的。我在JS上遇到了可写属性。

var x = {name:'JohnSnow'};

Object.defineProperty(x, 'name', {
   writable: false
};
Run Code Online (Sandbox Code Playgroud)

现在更改name属性对对象没有影响x。这是可以理解的,因为我将其writable属性更改为false

但是,我阅读的所有文档(包括https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties#Parameters)都表示此属性是false默认属性。

如果默认writable将设置为false,则对象默认情况下不应该是不可变的,并且仅应将其设置writable为才可变true

我在这里理解对象属性的概念是错误的,因为我认为JS中的所有对象都具有此属性,config并且每个对象都具有writable属性。

javascript object

4
推荐指数
1
解决办法
49
查看次数

当数组的索引与-1比较时

我已经看到多个代码,其中数组的索引与-1比较,如

if (index === -1)
Run Code Online (Sandbox Code Playgroud)

这究竟是做什么的?

我相信我们不能将值存储在负索引中,至少作为数组元素.(我知道,作为数组的属性,我们确实可以做到这一点).但那么上述条件何时会返回真或假?

javascript arrays

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

为什么使用切片克隆列表会影响原始列表

下面是我将数组中的对象更改为字符串的代码.无法弄清楚它为什么影响原始数组.如果我是对的,切片应该克隆数组?

var cloned = $scope.selected.items.slice(0);
cloned.forEach(function (cluster) {
  cluster.status = cluster.status.name;
})
ObjToPost.MO = cloned;
console.log("consoling the cluster list", ObjToPost.MO);
console.log("consoling the original cluster list", $scope.selected.items);
Run Code Online (Sandbox Code Playgroud)

安慰后两个阵列都是一样的

javascript arrays

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

ui-grid 不显示提供给它的完整行数

我已经使用 ui-grid 一段时间了。最近我遇到了一个网格问题,如果我传递一个稍微大的数据集(比如 50 行),网格不会显示它们。

当我调试并查找我的 $scope.gridOption.data 对象时,它似乎包含所有元素,但仍然只显示了几个(大约 10 个)。

当我尝试通过单击标题进行排序时,会出现更多行。(有时 1 或 2 个)

这不规则,也没有规律。对于不同的数据集,它随机发生。

我正在使用ui-grid - v3.2.6并且我有一个div带有 amax-heightscroll其他的网格表。我在具有类似实现的页面上有多个这样的网格,但这个问题目前似乎出现在某个网格上。

我可以起草一个plunker,但它并没有真正的帮助,因为这个问题是随机的,而且我有一个基本的ui-grid实现。

我跟着这个链接https://github.com/angular-ui/ui-grid/issues/424,但是我无法理解它,我仍然被卡住了。

似乎这是一个已知且未修复的错误。但是有什么可行的解决方案吗???

任何帮助表示赞赏..

angularjs angular-ui-grid ui-grid

3
推荐指数
2
解决办法
3352
查看次数

无法使用Angular Service处理onbeforeunload事件

我在我onbeforeUnload的一项服务中对我的活动进行了以下回调.在我的app.run块中我有:

window.onbeforeunload = Services.beforeWindowClose;

这个方法是在服务中:

this.beforeWindowClose = function (event) {
            var currentState = $state.current.name;
            if (currentState !== constant.LOGOUT) {
                $rootScope.$broadcast("close");
                if (Utilities.isSavePending)
                    event.returnValue = constant.MSG;
            }
        }
Run Code Online (Sandbox Code Playgroud)

在我的控制器中,我有:

$scope.$on("close", function () {
            Utilities.isSavePending = vm.save; //sets it to true
        })
Run Code Online (Sandbox Code Playgroud)

现在假设事件在角度上是同步的,这段代码应该在窗口关闭时给我一个弹出窗口.但是,这会直接关闭我的窗口.

我的意图是,每当用户关闭窗口时,我都会引发一个事件,看看我的控制器中是否有未保存的数据.如果有一些未保存的数据,浏览器不应该关闭并弹出,而如果没有未保存的数据,浏览器应该关闭.

我在做什么或者理解错了什么?

javascript onbeforeunload javascript-events angularjs

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

无法解决 Angular Universal 的依赖关系

我需要将 SSR 用于我现有的 Angular 项目之一。为此,我已将我的一个项目从 v8 迁移到 v13.0.0,这本身就花费了很多时间。

\n

然而,现在该应用程序在 v13.0.0 上运行良好,我尝试使用以下命令向其添加 SSR

\n
\n

ng 添加@nguniversal/express-engine

\n
\n

此命令似乎添加了通用版本 13.0.1,但它一直失败,并出现类似于以下内容的错误:

\n
\n

D:\\my-app-universal>ng add @nguniversal/express-engine i Using package\nmanager: npm \xe2\x88\x9a Found compatible package version:\n@nguniversal/express-engine@13.0.1. \xe2\x88\x9a Package information loaded.

\n

The package @nguniversal/express-engine@13.0.1 will be installed and\nexecuted. Would you like to proceed? Yes npm ERR! code ERESOLVE npm\nERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR!\nWhile resolving: my-app-universal@0.0.0 npm ERR! Found:\n@angular/animations@13.0.3 npm ERR! node_modules/@angular/animations\nnpm ERR! @angular/animations@"~13.0.0" from the …

node.js npm angular-universal angular

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

无法使用 primeng <p-datatable> 虚拟滚动延迟加载

我正在尝试使用 primeng 对大量数据实现延迟加载<p-datatable>。我已经完成了官方网站上记录的所有内容,但是我无法使其工作。

回调onLazyLoad仅在加载表时运行一次。它不会按预期在每次滚动时触发。

<div style="max-height:300px; border:1px solid black;overflow-y:auto">
      <p-dataTable #pocListref [value]="data" rowHover="true" [(selection)] = "selectedData" scrollable="true" scrollHeight="200px" [rows]="4"
      [style]="{'margin-top':'30px'}"  [paginator]="true" [rowsPerPageOptions]="[5,10,20]"
        [lazy]="true" [totalRecords]="totalRecords" (onLazyLoad)="lazyLoad($event)">
        <p-column header="Id">
        <ng-template pTemplate="body" let-index="rowIndex">
            {{index}}
        </ng-template>
        </p-column>
        <p-column  selectionMode="multiple" [style]="{'width':'5%'}"></p-column>
        <p-column field="name" header="Name"[sortable]="true"></p-column>
        <p-column field="age" header="Age" [sortable]="true"></p-column>
        <p-column field="company" header="Company" [sortable]="true"></p-column>
      </p-dataTable>
  </div>
Run Code Online (Sandbox Code Playgroud)

对于分页器实现来说,同样可以正常工作。我注意到,仅当我不使用属性时,它才适用于分页器virtualScroll,这是有道理的,但不知何故 virtualScroll 不会对滚动产生任何影响。

我知道已经有类似的问题,但仍然得到回答。

有人成功使用虚拟滚动和延迟加载吗?任何建议都会有用的。

lazy-loading primeng angular primeng-datatable

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

单击行展开 prime-ng 的 p 表行

此处的链接https://www.primefaces.org/primeng/#/table/rowexpansionp-table显示了可以通过单击使用指令的第一列来展开行的示例pRowToggler

我试图通过单击行上任意位置的行来实现这种切换。

我曾尝试寻找这样的例子,但找不到。[pRowToggler]我也尝试过在该行上使用ng-template,但这也不起作用。

有人可以指导我如何实现这种行为吗?

primeng angular primeng-datatable

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

如何使用 Postgres 数据库 URL 字符串传递证书路径以进行 SSL 连接

我正在尝试通过 SSL 为我的 Spring 启动应用程序保护与 AWS RDS 实例的连接。我查看了几个博客和官方文档,并相应地修改了我的连接字符串以包含与 SSL 连接相关的某些参数。

我将我的证书放置在资源中的证书文件夹中。以下是我尝试传递证书路径的方法:

jdbc:postgresql://myamazondomain.rds.amazonaws.com:5432/db_name?sslmode=verify-full&sslrootcert=/cert/rds-ca-cert_name.p12&password=my_passwrord
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

jdbc:postgresql://myamazondomain.rds.amazonaws.com:5432/db_name?sslmode=verify-full&sslrootcert=/src/main/resources/cert/rds-ca-cert_name.p12&password=mypassword
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试从 ECS 容器连接到 RDS 时,收到以下错误:

ERROR com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Exception during pool initialization.
org.postgresql.util.PSQLException: Could not open SSL root certificate file /cert/rds-ca-cert_name.p12.

at org.postgresql.ssl.LibPQFactory.<init>(LibPQFactory.java:120)

at org.postgresql.core.SocketFactoryFactory.getSslSocketFactory(SocketFactoryFactory.java:61)

at org.postgresql.ssl.MakeSSL.convert(MakeSSL.java:33)

at org.postgresql.core.v3.ConnectionFactoryImpl.enableSSL(ConnectionFactoryImpl.java:435)

at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:94)

at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192)

at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)

at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)

at org.postgresql.Driver.makeConnection(Driver.java:454)
Run Code Online (Sandbox Code Playgroud)

有人可以建议这里有什么错误吗?将类路径中存储的证书传递给 jdbc 连接字符串的正确方法是什么?

postgresql ssl jdbc ssl-certificate amazon-rds

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

如何在 Azure 机器人消息文本中添加超链接

我最近开始在 Node js 中创建一个 Azure 机器人。我想在机器人响应之一中添加一个超链接,并在用户单击它后发送主动响应。就像是:

Please click this link to complete the payment

并且该链接应该是一个将重定向到端点的超链接。

我试图找到一种方法来实现它,但到目前为止,我还没有能够实现。我看过以下链接:

https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-send-activity?view=azure-bot-service- 4.0

https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-howto-add-media-attachments?view=azure-bot-service-4.0&tabs=javascript

有人可以建议我实现这一目标的方法吗?

node.js botframework azure-bot-service

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

md-select检查md-options中重复选项的标准是什么

我一直在我的项目中使用Angular Material一段时间.使用md-select时,我遇到了一个问题,即我得到重复的md-option值错误.

我知道md-options采用唯一值,我正在为md-options分配一个数组.但是,这是一个对象数组.所以我想知道用于区分对象的标准是什么.API没有说太多.

我的用例要求根据另一个md-select的选择更改md-select的md-options.因此,我正在观看第一个md-select的选择,并在其更改时触发监视并更新第二个md-select的md-options.

以下是我用于将数组分配给md-options的方法:

$scope.$watch('search.selectedTrades', function(newTrades, oldTrades) {
    if ((newTrades.length === 0)) {
        $rootScope.search.selectedTrades = oldTrades;
        return;
    }
    if ($rootScope.search.selectedTrades && $rootScope.search.selectedTrades.length > 0) {
        if (!$rootScope.identity.isClusterManager) {
            $rootScope.search.selectedTrades = newTrades;
            SearchFilterData.setSelectedTrades(newTrades);
            $rootScope.search.selectedClusters = [];
            $scope.clusters = [];
            $scope.subareas = [];
            var clusterKeys = [];
            $rootScope.search.selectedTrades.forEach(function(t) {
                t.lstClusters.forEach(function(c) {
                    if (clusterKeys.indexOf(c.ClusterKey) == -1) {
                        clusterKeys.push(c.ClusterKey);
                        $scope.clusters.push(c);
                    }
                })
            })
        }
    } else {
        $scope.clusters = [];
        $scope.subareas = [];
        $rootScope.search.selectedClusters = [];
        $rootScope.search.selectedSubAreas = [];
        SearchFilterData.setSelectedTrades($rootScope.search.selectedTrades);
    }
});
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,clusterKey是每个对象的唯一实体.所以我用它来将唯一值推送到数组中.然而,在我选择和取消选择各种选项之后,这在几个随机场景中发生.请告知我做错了什么以及标记两个对象重复的标准是什么

angularjs angular-material

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

How can we limit the number of suggestions displayed by auto-complete in Angular Material

I am using Angular material auto-complete to display suggestion based on user typing. As user types I make API calls and bring the data to be displayed. Now in some cases the results are huge in number say 500-1000 and hence the DOM stops responding.

I am looking for a way where I can limit these suggestion to some specific values and then increase them (on say scroll).

I checked if I could use limitTo with it like we use …

angularjs angular-material

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