小编lef*_*ost的帖子

如何在 Svelte 中的不同事件上触发相同的功能

我有:

<a href={link} on:click={() => func(param)} on:auxclick={() => func(param)}>
   click
</a>
Run Code Online (Sandbox Code Playgroud)

有什么方法可以将on:click和组合on:auxclickon:click|auxclick,或者类似这种效果的东西吗?(下面的代码给了我一个语法错误。)

<a href={link} on:click|auxclick={() => func(param)}>
   click
</a>
Run Code Online (Sandbox Code Playgroud)

编辑:为了更清楚的描述

javascript svelte

8
推荐指数
2
解决办法
2033
查看次数

从文本文件中读取后,结果显示不正确

我编写了一个程序,从文本文件的每一行读取四个变量(三个字符串和一个字符).但是当我显示变量时,每行末尾会弹出一个意外的字符.(我确保变量的长度足够大).

为什么是这样?(再次溢出缓冲区?)我该如何解决这个问题?

文本文件内容:

M0001 Cool Name F 123-456789
M0002 Name Cool M 987-654321

码:

    #include <stdio.h>
    #include <stdlib.h>

    int main() {
        FILE *text;

        char id[6], name[101], gender, contact[13];

        text = fopen("test.txt", "r");
        while (fscanf(text, "%s %[^\n]s %c %s\n", id, name, &gender, contact) != EOF)
            printf("%s %s %c %s\n", id, name, gender, contact);
        fclose(text);

        return 0;

}
Run Code Online (Sandbox Code Playgroud)

我期望的输出:

M0001 Cool Name F 123-456789
M0002 Name Cool M 987-654321

我得到的是:

M0001 Cool Name F 123-456789 1?4
M0002 Name Cool M 987-654321 1?4

c string stdio text-files

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

将对象作为构造函数中的参数传递

我正在尝试将对象作为参数传递给构造函数.是否允许以下​​代码?特别是我进入ToyotaCorolla进入的部分Car car,然后进入String brandString model.

public class Car {
    private String brand, model;

    public Car(String brand, String model) {
        this.brand = brand;
        this.model = model;
    }

    // getters and setters
}

public class Customer {
    private String name;
    private Car car;

    public Customer(String name, Car car) {
        this.name = name;
        this.car = car;
    }

    // getters and setters
}

public class Service {
    Customer customer = new Customer("John", "Toyota", "Corolla");
}
Run Code Online (Sandbox Code Playgroud)

java

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

标签 统计

c ×1

java ×1

javascript ×1

stdio ×1

string ×1

svelte ×1

text-files ×1