gpt4 book ai didi

javascript - 在 Ember JS 中使用模型作为 View 元素类名

转载 作者:太空宇宙 更新时间:2023-11-03 18:29:20 24 4
gpt4 key购买 nike

在 Ember 模型中,我有一个分配给模型的数字优先级;我需要将其传递给 Ember View 以用作 CSS 类,最好与字符串“importance-”连接。因此对于重要性为 5 的模型,它会将类“importance-5”添加到 Ember 的 View 生成的 div 中。但我似乎无法找到一种从我的 Ember View 访问该模型数据的简单方法——我在这里缺少什么?

最佳答案

可能需要一个 jsfiddle 来完全理解你想要完成的事情,但一般来说, Controller 就是这个地方。正如 Ember 指南所说:

“ Controller 允许您使用显示逻辑装饰您的模型。”

关键是将 Controller 的内容属性设置为事件模型。然后 Controller 上就会有一个计算属性:

importance: function() {
return 'importance-' + this.get('priority');
}.property('priority')

从那里你可以使用 classBinding using {{view YourViewName classBinding=importance}}

关于javascript - 在 Ember JS 中使用模型作为 View 元素类名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20168147/

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