titaniumappcelerator-titaniumlistviewitemtitanium-alloy

Titanium ListView template conditional rendering


Does anyone know how it would be possible to conditional render a view in the list view template based on the passed in bindId ?

I have a template which should show a view only if the value if the label that is passed in is not empty.

<View class="productBannerLabelWrapper productBanner1">
   <Label class="productBannerLabel" bindId="productBanner1" />
</View>

The label has a view around it, because the label needs a collared background which is larger than the label itself.

Thank for helping out


Solution

  • When you fill you item array you can set the visible property like this:

    var prop = {
      productBanner1: {
         text: "Text",
         visible: (checkValue)?1:0
      }
    }
    items.push(prop);
    $.list_section.items = items;
    

    with Alloy:

    add a databinding to the visible parameter like productBanner:visible="{isVisible}" and use a dataTransform to change the module before assigning it:

    function transformFnc(model) {
        return {
            otherStuff: model.attributes.otherStuff
            isVisible: (checkValue)?1:0
        }
    }