gpt4 book ai didi

javascript - 在 Aurelia Compose 的 View 模型中访问模型

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:01:13 26 4
gpt4 key购买 nike

因此根据标题根据数据将 UI 动态渲染到 DOM 中 here (向下滚动一点)。

<template repeat.for="item of items">
<compose model.bind="item" view-model="widgets/${item.type}"></compose>
</template>

如果你更简单地理解:

<compose model.bind="item" view-model="itemViewModel.js"></compose>

如果我有一个 itemViewModel.html 和一个 itemViewModel.js,它们都会成功加载。但是,如何访问 itemViewModel.js 中的绑定(bind)模型?

我尝试使用 bindable

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

export class ItemViewModel {
@bindable model;

constructor() {
console.log("using bindable", this);
}
}

这可能吗?

最佳答案

<compose model.bind="item"将调用一个方法 activate(model)在你的 View 模型中给你 item .

// the model received here is the *item* from the above <compose
activate(model){
this.model = model;
}

如果你想在绑定(bind)中传递多个模型,你可以这样做

<compose model.bind="{item: item, value: value}"

然后你得到:

activate(model){
this.item = model.item;
this.value = model.value;
}

关于javascript - 在 Aurelia Compose 的 View 模型中访问模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37652847/

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