Dashcode - 价值转换器的乐趣

发布于 2024-09-28 09:14:17 字数 594 浏览 3 评论 0原文

我正在创建一个 Dashcode 应用程序,用于显示赢得一项或多项奖项的产品。

数据源对于产品可能赢得的每个奖项都有一个列/字段(产品可能赢得多个奖项)。如果他们赢得了该奖项,则该列为“Y”;如果没有,则该列为空。

因此,我将数据源中的列绑定到图像对象,然后使用值转换器为图像设置正确的 src(如果他们赢得了奖项)。这工作得很好并且只需要很少的代码。就像这样:

myHasGoldAward = Class.create(DC.ValueTransformer,{
transformedValue: function(value){
    if (value == 'Y') {
        value = "Images/GoldAward.png";
}
    return value;
}

问题是我绑定的列仅指示他们是否赢得了特定级别的奖项(即金、银、铜),但还有另一列指示产品类型(即书籍、玩具、音频、视频)。每种不同类型的产品的奖项标志都不同。金图书奖看起来与金玩具奖不同。

我需要能够从我的值转换器中访问其他列,以便能够为奖项设置正确的图像。

有谁知道从值转换器内部访问数据源中另一列的语法?

谢谢!

I'm creating a Dashcode App that displays products that have won one or more awards.

The Data Source has a column/field for each award that the product may win (products may win multiple awards). The column has 'Y' if they won that award and is null if they didn't.

So I'm binding the column from the data source to an image object and then using a Value Transformer to set the correct src for the image if they won the award. This works fine and very little code is required. Just something like this:

myHasGoldAward = Class.create(DC.ValueTransformer,{
transformedValue: function(value){
    if (value == 'Y') {
        value = "Images/GoldAward.png";
}
    return value;
}

The wrinkle is that the column I'm binding to only indicates if they won a certain level award (ie. Gold, Silver, Bronze), but there's another column that indicates the type of product (ie. Book, Toy, Audio, Video). The logo for the award is different for each of the different types of products. The Gold Book award looks different than the Gold Toy award.

I need to be able to access the other column from within my Value Transformer in order to be able to set the right image for the Award.

Does anyone know the syntax to access another column in a data source from inside a value transformer?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文