datasourceconcatenationdashcode

Dashcode - how do you combine two values from one datasource


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?

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.

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.


Solution

  • 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!!!