Aurelia反复绑定.因为不起作用
Aurelia binding in repeat.for not working
我正试图在repeat.for中的aurelia组件上设置一个可绑定的值,但它似乎没有任何影响。
<event-summary repeat.for="event of events" event.bind="event" is-favorite="true"></event-summary>
在视图模型中
事件摘要.js
@bindable('isFavorite')
@bindable('event')
export class EventSummary {
bind(bindingContext) {
if(bindingContext.isFavorite == null) {
this.isFavorite = false;
}
}
}
事件设置正确,但无论我尝试什么,isFavorite总是未定义的(isFavorite.bind="[some-vm-value]")也返回未定义的。有人能告诉我为什么吗?
感谢
is-favorite.bind="true"
应该可以工作。is-favorite="true"
也应该工作,尽管在这种情况下,isFavorite可绑定属性将被分配字符串'true'
。以下是两者的可运行示例:https://gist.run/?id=7044b0c37b53bb66e833d461f41dae2f
我从未使用过bind()
函数,但通常情况下,您的作用域中有isFavorite
,如this.isFavorite
。你也可以在构造函数中进行null检查
这对我很有效:
import {bindable} from 'aurelia-framework';
export class Testelement {
@bindable item
@bindable isFavorite
constructor() {
console.log(this.isFavorite);
console.log(this.item);
}
bind(bindingContext, overrideContext) {
console.log("bc ", bindingContext); //no item or isFavorite defined here
console.log("oc ", overrideContext);//no item or isFavorite defined here
}
}
<testelement item.bind="element" repeat.for="element of data" is-favorite="true"></testelement>
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- 监视函数从服务返回不起作用,但作用域函数起作用
- 幻灯片滚动javascript不起作用
- 简单的javascript在Shopify中不起作用
- Recaptcha在IE7和IE8中不起作用
- Ember Data DS.Model's set函数不起作用
- $(this).attr({class:“activeTab”});不起作用,因为这是未定义的
- Aurelia反复绑定.因为不起作用
- AJAX调用不起作用,因为它继续转到链接
- 类绑定在 emberjs 中不起作用,因为不检查属性
- $(..).工具提示不起作用,因为 jQuery 1.9.2 由于旧的 jQuery UI 1.8.16 库而不起作用?
- ng路由不起作用.我不知道错误是什么,因为控制台中没有显示任何内容
- Flowplayer JS API 不起作用,因为 Flowplayer 未“加载”
- getElementByID 不起作用,因为字段在某种框架中,我如何访问它
- 向上滚动事件,因为铬不起作用
- 织物 js 粗斜体不起作用,因为 JSON 中的字体样式对象
- 因为让循环不起作用
- “返回假;”,因为表单提交不起作用
- 使用单词'英语'因为变量/对象名称在javascript中不起作用
- 引用类内的变量..当“;这个"不起作用,因为我们处于函数中