Dashcode-如何合并来自一个数据源的两个值 [英] Dashcode - how do you combine two values from one datasource

查看:101
本文介绍了Dashcode-如何合并来自一个数据源的两个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Dashcode中,如果我有一个数据源,该数据源具有两个名为 FirstName和 Last Name的字段,那么如何在列表视图中将这两个字段连接为一个文本字段?

In Dashcode, if I have a dataSource that has, for example, 2 fields called 'FirstName' and 'Last Name', how do I concatenate the 2 fields into one text field in a list view?

我相当确定必须使用值转换器,所以说我将 FirstName字段分配给文本字段,并添加值转换器...然后将'LastName'值添加到转换器中的'value'变量中。

I'm fairly sure it must be to use a value transformer, so say that I assign the 'FirstName' field to the textfield, and add a value transformer... how do I then add the 'LastName' value to the 'value' variable in the transformer.

我确定这与dashcode.getDataSource和valueForKeyPath有关,我认为接近解决方案,但看起来似乎有点笨拙,因此不胜感激。

I'm sure it's to do with dashcode.getDataSource and valueForKeyPath and I think I'm close to the solution but it all seems a bit ungainly so any help would be much appreciated.

推荐答案

正确-您需要使用一个值转换器。

Correct - you need to use a Value Transformer.

在该转换器中,您应编写以下代码:

In the Transformer, you would code as follows:

itemDescription = Class.create(DC.ValueTransformer,{
    transformedValue: function(value){

    var itemDataSource = dashcode.getDataSource('itemsList'); // The Data Source Name here
    var lastName = itemDataSource.selection().valueForKey('lastName'); // Presumes you have a field called lastName
    return value + " " + lastName;
    }
});

希望这会有所帮助-我为此奋斗了一天!!!

Hope this helps - I battled with this for a day!!!

这篇关于Dashcode-如何合并来自一个数据源的两个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆