gpt4 book ai didi

javascript - Aurelia 简单绑定(bind)不起作用

转载 作者:行者123 更新时间:2023-12-02 16:12:59 24 4
gpt4 key购买 nike

我有一个非常简单的绑定(bind),但它没有像我期望的那样工作:

app.js:

export class PupilsViewer {

pupilsInfo = [
{ name: 'John' },
{ name: 'Eric' },
{ name: 'Martin' },
{ name: 'Simon' }
];

}

app.html:

<template>
<require from="./pupil"></require>
<pupil repeat.for="pupilInfo of pupilsInfo" info="${pupilInfo}"></pupil>
</template>

pupil.js:

import {bindable} from 'aurelia-framework';

export class Pupil {
@bindable info = { name: 'unknown' };
}

pupil.html:

<template>
<div>Name: ${info.name}</div>
</template>

这会产生以下输出:

Name: unknown
Name: unknown
Name: unknown
Name: unknown

虽然我预料到了:

Name: John
Name: Eric
Name: Martin
Name: Simon

最佳答案

现在我也遇到了同样的问题。这似乎是一个打字错误问题。尝试更改或删除可绑定(bind)项的驼峰式大小写。但你的绑定(bind)也不行。

export class PupilsViewer {

pupils = [
{ name: 'John' },
{ name: 'Eric' },
{ name: 'Martin' },
{ name: 'Simon' }
];

}

app.html

<template>
<require from="./pupil"></require>
<pupil repeat.for="pupil of pupils" info.bind="pupil"></pupil>
</template>

pupil.js

import {customElement, bindable} from 'aurelia-framework';

@customElement('pupil')
@bindable('info')
export class Pupil {

}

关于javascript - Aurelia 简单绑定(bind)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29963074/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com