[英]Access model in view model in Aurelia Compose
So according to the heading Dynamically Render UI into the DOM based on Data here (scroll down a bit). 因此,根据标题动态呈现UI到基于数据的DOM 这里 (向下滚动位)。
<template repeat.for="item of items">
<compose model.bind="item" view-model="widgets/${item.type}"></compose>
</template>
If you take it more simply: 如果你更简单地说:
<compose model.bind="item" view-model="itemViewModel.js"></compose>
If I have an itemViewModel.html
and a itemViewModel.js
, they both get successfully loaded. 如果我有
itemViewModel.html
和itemViewModel.js
,它们都会成功加载。 However, how do you access the bound model in the itemViewModel.js
? 但是,如何在
itemViewModel.js
访问绑定模型?
I tried using the bindable
. 我尝试使用
bindable
。
import {bindable, bindingMode} from 'aurelia-framework';
export class ItemViewModel {
@bindable model;
constructor() {
console.log("using bindable", this);
}
}
Is this possible? 这可能吗?
<compose model.bind="item"
will call a method activate(model)
in your viewmodel and give you the item
. <compose model.bind="item"
将在您的viewmodel中调用方法activate(model)
并为您提供该item
。
// the model received here is the *item* from the above <compose
activate(model){
this.model = model;
}
If you want to pass multiple models in the bind you can do 如果你想在绑定中传递多个模型,你可以做到
<compose model.bind="{item: item, value: value}"
Then you get: 然后你得到:
activate(model){
this.item = model.item;
this.value = model.value;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.