小编sat*_*ish的帖子

如何渲染没有标题行的 Angular 9 mat-table?

我正在使用 Angular 9。如何构造一个没有表头行(th)的 mat-table?听起来很傻,但如果我这样做

\n
<table mat-table *ngIf="isMobile" #mobile_table [dataSource]="dataSource">\n  <ng-container matColumnDef="item">\n    <td mat-cell *matCellDef="let item_stat">\n      <div class="smallHeading">\n        {{ item_stat.max_date }} m\n      </div>\n      <div class="mainRow divider">\n        <a href="{{ item_stat.mobile_path }}">{{ item_stat.title }}</a> \xc2\xb7\n        {{ getScore(item_stat) }}\n      </div>\n    </td>\n  </ng-container>\n\n  <tr mat-header-row *matHeaderRowDef="mobileDisplayedColumns"></tr>\n  <tr mat-row *matRowDef="let row; columns: mobileDisplayedColumns;" [ngClass]="getRowClass(row)"></tr>\n</table>\n
Run Code Online (Sandbox Code Playgroud)\n

它产生错误

\n
ERROR TypeError: Cannot read property 'template' of undefined\n    at MatHeaderRowDef.extractCellTemplate (table.js:567)\n    at table.js:2522\n    at Function.from (<anonymous>)\n    at MatTable._getCellTemplates (table.js:2512)\n    at MatTable._renderRow (table.js:2467)\n    at table.js:2326\n    at Array.forEach (<anonymous>)\n    at …
Run Code Online (Sandbox Code Playgroud)

html-table angular mat-table angular9

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

如何查看我对特定 Git 存储库的权限?

我想知道在 GitHub 中如何查看我对特定存储库的权限?如果网址是

https://github.com/org/repo
Run Code Online (Sandbox Code Playgroud)

我在哪里可以找到我拥有哪些权限(如果有)?

permissions github

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

在Javascript(但不是Node)中,如何分割两个Uint8Arrays?

我正在使用浏览器内的Javascript,而不是NodeJS.我有两个Uint8Arrays ......

var d1 = new Uint8Array([255, 255, 255, 255, 255, 255, 255, 255])
var d2 = new Uint8Array([255, 255, 255, 255, 237, 49, 56, 0])
Run Code Online (Sandbox Code Playgroud)

每个元素都有8个元素,整数在0到255之间.每个数组代表一个更大的数字.例如,第一个数组表示正整数

0xffffffff
Run Code Online (Sandbox Code Playgroud)

我的问题是如何将d1除以d2得到结果?我读到Javascript中一个整数的最大值是2 ^ 53,我相信它比我可以拥有的最大数字少.我不关心结果的对象类型是什么,但是Uint8Array很好.

javascript arrays division bigint uint8array

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

如何初始化 Uint8Array?

我想创建一个包含 8 个元素的 Uint8Array。我试过这个

var myarr = new Uint8Array(255,255,255,255,40,92,143,2);
Run Code Online (Sandbox Code Playgroud)

但是当我跑

myarr.length
Run Code Online (Sandbox Code Playgroud)

当我期望答案是“8”时,我会返回“255”。我假设我在初始化步骤中做错了什么,但不知道那是什么。

javascript arrays initialization uint8array

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

我是否需要将 __init__.py 放置在通向我的类的目录树中的每个目录中?

我正在使用 Python 3.6 构建 Django 项目。我已经创建了这个目录结构...

project
- manage.py
- scripts
  - run_commands.py
- commons
  - util
    - __init__.py
    - my_class.py
Run Code Online (Sandbox Code Playgroud)

init.py的内容是

from . import my_class
Run Code Online (Sandbox Code Playgroud)

在另一个班级中,我尝试像这样导入我的 MyClass

from commons.util import MyClass
Run Code Online (Sandbox Code Playgroud)

但我收到这个错误

ModuleNotFoundError: No module named 'commons'
Run Code Online (Sandbox Code Playgroud)

我是否正确创建了init .py ?

django import module python-3.x

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

在 Spring Boot 2 中,如何自动生成我的数据库并将模式生成命令记录到文件中?

我在 Java 11 中使用 Spring Boot 2.1。我正在使用 Maven 来构建我的工件。在本地运行时,我喜欢 Spring JPA 指令,它让我自动创建数据库......

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.show-sql=true
Run Code Online (Sandbox Code Playgroud)

我也喜欢让我自​​动创建文件的指令......

spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata
spring.jpa.properties.javax.persistence.schema-generation.scripts.action=update
spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=update.sql
Run Code Online (Sandbox Code Playgroud)

然而,当我在我的 src/main/resources/application.properties 中结合两者时......

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.show-sql=true
spring.jpa.properties.javax.persistence.validation.mode=none

spring.datasource.url=jdbc:postgresql://${PG_DB_HOST:localhost}:5432/${PG_DB_NAME}

spring.datasource.username=${PG_DB_USER}
spring.datasource.password=${PG_DB_PASS}

spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata
spring.jpa.properties.javax.persistence.schema-generation.scripts.action=update
spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=update.sql
Run Code Online (Sandbox Code Playgroud)

似乎“spring.jpa.properties.javax.persistence”优先,我的架构更改不会针对数据库自动运行。有没有办法配置同时发生的事情——更改被记录到文件中并自动针对我的数据库运行?

jpa maven spring-data-jpa spring-boot spring-boot-2

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

在 Rails migraiton 中,如何将列的默认值设置为 NOW() 而不是运行迁移时的时间?

我有一个 PostGres 9.4 数据库。我想将 DATETIME 列的默认列类型更改为创建记录的时间。我认为这是正确的方法,因为这是我的 Rails 迁移

class ChangeDefaultValueForStratumWorkerSubmissions < ActiveRecord::Migration[5.1]
  def change
    change_column_default(:stratum_worker_submissions, :created_at, 'NOW')
  end
end
Run Code Online (Sandbox Code Playgroud)

但是当我查看数据库时,默认时间戳显示为我运行迁移的时间,而不是我想要的表达式。我如何编写一个可以实现我想要的迁移?

      Column       |            Type             |                                 Modifiers
-------------------+-----------------------------+----------------------------------------------------------------------------
 id                | integer                     | not null default nextval('stratum_worker_submissions_id_seq'::regclass)
 stratum_worker_id | integer                     |
 created_at        | timestamp without time zone | not null default '2018-04-04 19:46:22.781613'::timestamp without time zone
Run Code Online (Sandbox Code Playgroud)

postgresql ruby-on-rails default-value rails-migrations ruby-on-rails-5

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

在 Rails 控制台中调用控制器方法时,如何将参数传递给控制器​​方法?

我正在使用 Rails 5。我有这个控制器......

class MyObjectsController < ApplicationController

  def create
    my_object = MyService.build(create_params)
Run Code Online (Sandbox Code Playgroud)

我想在 rails 控制台中调用 create 方法,但出现此错误...

irb(main):007:0> MyObjectsController.new.create(:id => "abc")
Traceback (most recent call last):
        2: from (irb):7
        1: from app/controllers/my_objects_controller.rb:4:in `create'
ArgumentError (wrong number of arguments (given 1, expected 0))
Run Code Online (Sandbox Code Playgroud)

如何将参数传递给我的控制器方法?

console controller ruby-on-rails ruby-on-rails-5

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

如何配置 @PreAuthorize 来识别登录用户的 ID?

我正在尝试创建一个 Spring Boot 2.1 应用程序。我创建了以下休息控制器......

@RestController
@RequestMapping("/api/users")
public class UserController {
...

    @PutMapping("/{id}")
    @PreAuthorize("authentication.principal.id == #id")
    public ResponseEntity<User> update(@RequestBody User user, @PathVariable UUID id) {
        final User updatedUser = userService.update(id, user);
        if (updatedUser == null) {
            return ResponseEntity.notFound().build();
        } else {
            return ResponseEntity.ok(updatedUser);
        }
    }
Run Code Online (Sandbox Code Playgroud)

唯一能够访问此端点的人应该登录,并且他们的 ID 应与参数的 ID 匹配。但是,上面的操作失败并出现以下错误......

org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'id' cannot be found on object of type 'org.springframework.security.core.userdetails.User' - maybe not public or not valid?
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:217) ~[spring-expression-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:104) ~[spring-expression-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:51) ~[spring-expression-5.2.7.RELEASE.jar:5.2.7.RELEASE] …
Run Code Online (Sandbox Code Playgroud)

authorization annotations spring-security spring-boot spring-restcontroller

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

如何在单元测试中伪造一个Recaptcha?

我正在使用Rails 5,并且有一个带有Google Recaptcha的表单。我为此使用Rails宝石

gem "recaptcha", require: "recaptcha/rails"
Run Code Online (Sandbox Code Playgroud)

所以我有一个简单的表格

<%= form_for @comment, :html => {:class => "commentsForm"} do |f| %>
  <div class="field">
    <%= f.label :description, 'Your Comments' %><br>
    <%= f.text_area :description %>
  </div>
  <%= recaptcha_tags %>
  <div class="actions">
    <%= submit_tag 'Submit', :class => 'btn-feedback' %>
  </div>
<% end %>
Run Code Online (Sandbox Code Playgroud)

而我要处理的控制器是

  def create
    @comment = Comment.new(params[:comment].permit(:description))
    @comment.user = current_user
    if verify_recaptcha(model: @comment)
Run Code Online (Sandbox Code Playgroud)

但是我该如何编写单元测试来测试控制器方法呢?我不知道如何“伪造” recaptcha提交。这就是我所拥有的

  test "do submit comment" do
    post comments_url, params: { comment: { description: "Some comments"} }

    # Verify we …
Run Code Online (Sandbox Code Playgroud)

unit-testing controller ruby-on-rails recaptcha

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