小编Max*_*Max的帖子

Angular 6:ERROR TypeError:"......不是函数" - 但确实如此

我现在真的很困惑,因为我得到了ERROR TypeError: "_this.device.addKeysToObj is not a function".但我实现了这个功能,所以我不知道问题是什么或为什么它不可调用.我已经尝试使用Firefox和chrome的代码,两者都是通过相同的错误.

错误符合 this.device.addKeysToObj(this.result.results[0]);

这是我的班级:

export class Device {
    id: number;
    deviceID: string;
    name: string;
    location: string;
    deviceType: string;
    subType: string;
    valueNamingMap: Object;

    addKeysToObj(deviceValues: object): void {
        for (let key of Object.keys(deviceValues).map((key) => { return key })) {
            if (!this.valueNamingMap.hasOwnProperty(key)) {
                this.valueNamingMap[key] = '';
            }
        }
        console.log(this, deviceValues);
    }
}
Run Code Online (Sandbox Code Playgroud)

这就是电话:

export class BatterieSensorComponent implements OnInit {
    @Input() device: Device;
    public result: Page<Value> = new Page<Value>();

    //[..]

    ngOnInit() {
      this.valueService.list('', this.device).subscribe(
        res => …
Run Code Online (Sandbox Code Playgroud)

javascript typescript angular

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

Pytorch动态层数?

我试图指定动态的层数,但我似乎做错了。我的问题是,当我在这里定义 100 层时,我会在前进步骤中收到错误。但是当我正确定义图层时它会起作用吗?下面是简化的示例

class PredictFromEmbeddParaSmall(LightningModule):
    def __init__(self, hyperparams={'lr': 0.0001}):
        super(PredictFromEmbeddParaSmall, self).__init__()
        #Input is something like tensor.size=[768*100]
        self.TO_ILLUSTRATE = nn.Linear(768, 5)
        self.enc_ref=[]
        for i in range(100):
            self.enc_red.append(nn.Linear(768, 5))
        # gather the layers output sth
        self.dense_simple1 = nn.Linear(5*100, 2)
        self.output = nn.Sigmoid()
    def forward(self, x):
        # first input to enc_red
        x_vecs = []
        for i in range(self.para_count):
            layer = self.enc_red[i]
            # The first dim is the batch size here, output is correct
            processed_slice = x[:, i * 768:(i + 1) * 768] …
Run Code Online (Sandbox Code Playgroud)

pytorch pytorch-lightning

7
推荐指数
2
解决办法
7421
查看次数

Angular 7:Formvalidation,Validators.pattern 不起作用

我只需要一个来自匹配整数的验证。因此我使用pattern带有正则表达式的验证器(见下文)。此外,该字段不应为空,因此我添加了required验证器。

pattern错误永远不会被触发。我阅读了 angular 文档并查看了 的源代码,pattern但对我来说仍然没有意义。此外,我已经阅读了几乎所有与此主题相关的关于 stackoverflow 的问题。但我仍然无法弄清楚为什么该模式不起作用。

或许有大佬可以帮帮我,谢谢!

这是我的代码 component.ts:

// definition of the formcontrol
hours = new FormControl('', [
  Validators.required,
  Validators.pattern('^[0-9]*$'),
])

// for debugging
log() {
  console.log('required: ', this.hours.hasError('required'));
  console.log('pattern: ', this.hours.hasError('pattern'));
  console.log('Erros: ', this.hours.errors);
}
Run Code Online (Sandbox Code Playgroud)

模板:

<mat-form-field>
  <input matInput [formControl]="hours" (input)="log()"
    placeholder="Anzahl der ausbezahlten Überstunden" type="number">
  <mat-error *ngIf="hours.hasError('required') && !hours.hasError('pattern')">
    Anzahl der Überstunden fehlt!
  </mat-error>
  <mat-error *ngIf="!hours.hasError('required') && hours.hasError('pattern')">
    Anzahl muss eine Ganzzahl sein!
  </mat-error>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)

例子inputValue="": …

typescript angular angular-reactive-forms angular7

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

django get_available_name()得到一个意外的关键字参数'max_length'

我想用my django Model覆盖文件.因此,如果我上传'one'并稍后上传'two','two'应该覆盖'one'(在文件系统上).但是我收到了一个错误.

这是我的模特:

class StudentAssignment(models.Model):
    file0 = models.FileField(upload_to=use_solution_path, storage=OverwriteStorage(), validators=[validate_file_extension])
Run Code Online (Sandbox Code Playgroud)

这是存储.

import os
from django.conf import settings
from django.core.files.storage import FileSystemStorage


class OverwriteStorage(FileSystemStorage):
    def get_available_name(self, name):
        """
        Returns a filename that's free on the target storage system, and
        available for new content to be written to.
        """
        # If the filename already exists, remove it as if it was a true file system
        if self.exists(name):
            os.remove(os.path.join(settings.MEDIA_ROOT, name))
        return name
Run Code Online (Sandbox Code Playgroud)

错误:

  [...]
  File "/home/mb/.local/lib/python3.5/site-packages/django/db/models/fields/files.py", line 95, in save
self.name = …
Run Code Online (Sandbox Code Playgroud)

python django filefield

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

Angular 6:如何取消订阅 rsjx 间隔或计时器?

我认为这个问题很清楚。我找不到任何有关如何取消订阅 -rsjx操作的信息,例如interval or timer

我的组件:

public intervallTimer = interval(5000);

ngOnInit() {
  this.getValues();
  this.intervallTimer.subscribe(() => this.getValues());
}

// What I like to do is something like this, but "unsubscribe()" that's no function
somefunction(){
  this.intervallTimer.unsubscribe()
}
Run Code Online (Sandbox Code Playgroud)

typescript angular6

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

Python 子进程终止并超时

我正在使用 python 中的 subprocess 模块运行一些 shell 脚本。如果 shell 脚本运行时间过长,我喜欢终止子进程。我认为如果我将 传递timeout=30给我的run(..)陈述就足够了。

这是代码:

try:
    result=run(['utilities/shell_scripts/{0} {1} {2}'.format(
                        self.language_conf[key][1], self.proc_dir, config.main_file)],
                shell=True,
                check=True,
                stdout=PIPE,
                stderr=PIPE, 
                universal_newlines=True, 
                timeout=30,
                bufsize=100)
except TimeoutExpired as timeout:
Run Code Online (Sandbox Code Playgroud)

我已经用一些运行 120 秒的 shell 脚本测试了这个调用。我预计子进程会在 30 秒后被终止,但实际上该进程正在完成 120 秒的脚本,然后引发超时异常。现在的问题是如何通过超时终止子进程?

python subprocess

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

Angular 5:使用异步管道进行搜索-显示加载指示器

我正在asyncAnglur 5中实现一个搜索字段。当用户开始在搜索框中输入内容时,应该会显示加载指示符。当结果到达时,指示符应该被隐藏。

我尝试了这种方法,但是即使用户未输入任何内容,加载指示器也可见。那么实现此目标的最佳方法是什么?

我的模板:

<mdl-textfield #searchBox (keyup)="search(searchBox.value)" type="text" placeholder="Nach Kurs, Beteuer, Studiengruppe suchen..."></mdl-textfield>
<!--[...]-->
<div *ngIf="courses$ | async as courses">
  <ng-container *ngIf="courses.length; else noItems">
      <app-course *ngFor="let course of courses" [course]="course" [addAble]="true"></app-course>
  </ng-container>
  <ng-template #noItems><em>Kein Ergebniss für "{{searchBox.value}}"</em></ng-template>
</div>
Run Code Online (Sandbox Code Playgroud)

组件:

public courses$: Observable<Course[]>;
public searchCourseTerm = new Subject<string>();
public serachLoadingIndicator: boolean = false;

constructor(private courseService: CourseService) { }

gOnInit() {
  this.courses$ = this.searchCourseTerm.pipe(
    debounceTime(300),
    distinctUntilChanged(),
    switchMap((term: string) => this.courseService.searchCourse(term)),
  );
}

search(term: string ){
  this.searchCourseTerm.next(term);
}
Run Code Online (Sandbox Code Playgroud)

typescript angular angular5

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