титанов списък Преглед на динамично обвързване на данни

sdk: 3.5.1

Не съм запознат с listView механиката. Опитвам се да разбера как да приложа стойности на JSON данни към обвързаните свойства на шаблона на елемента.

Започвам с картографиране на данните

//example 
var data = ({data:json-data, index:'label'});

var _data = _.map(data, function(item, index) {
    return {
        properties: {
            categoryLabel: index,
            data: item

        }
    }
});

След това искам да го свържа с моя списък

$.activityDetailsList.sections[0].setItems(_data);

Според мен имам

<ListView defaultItemTemplate="activityDetailsListItemTemplate" id="activityDetailsList">
  <Templates>
    <ItemTemplate name="activityDetailsListItemTemplate">
      <Label bindId="categoryLabel" class="rowTitle" id="categoryLabel"/>
      <View bindId="rightSpacer" id="rightSpacer">
        <ImageView bindId="arrowImage" id="arrowImage"/>
      </View>
    </ItemTemplate>
  </Templates>
 <ListSection id="activityDetailsListSection">
    <ListItem template='activityDetailsListItemTemplate'/>
  </ListSection>
</ListView>

Когато преминавам през пет елемента, всичко, което получавам обратно, са празни редове със съответните стрелки.

въведете описание на изображението тук

Ето въпроса ми: Как да накарам categoryLabel текстовите стойности да се показват? Трябва ли да го дефинирам в шаблона? Тази част не ми е ясна. Мислех, че простото свързване на данните към шаблона е достатъчно. Очевидно не.


person Mike S.    schedule 27.01.2016    source източник


Отговори (1)


Какво най-накрая проработи при мен:

преглед на xml

<Alloy>
    <Window class="container">
        <ListView defaultItemTemplate="dailyActivitiesTemplate" id="activityList" top="30">
            <Templates>
                <ItemTemplate name="dailyActivitiesTemplate">
                    <View id="dailyActivities">
                        <View class="row" id="fundRow">
                            <Label class="rowTitle" id="fund" text="Fund: "/>
                            <Label bindId="fund" class="rowValue" id="fund"/>
                        </View>
                        <View class="row" id="amountRow">
                            <Label class="rowTitle" id="amount" text="Amount: "/>
                            <Label bindId="amount" class="rowValue" id="amount"/>
                        </View>
                        <View class="row" id="unitsRow">
                            <Label class="rowTitle" id="units" text="Units: "/>
                            <Label bindId="units" class="rowValue" id="units"/>
                        </View>
                        <View class="row" id="sourceRow">
                            <Label class="rowTitle" id="source" text="Source: "/>
                            <Label bindId="source" class="rowValue" id="source"/>
                        </View>
                        <View class="row" id="unitValueRow">
                            <Label class="rowTitle" id="unitValue" text="Unit Value: "/>
                            <Label bindId="unitValue" class="rowValue" id="unitValue"/>
                        </View>
                    </View>
                </ItemTemplate>
            </Templates>
            <ListSection>
                <ListItem template="dailyActivitiesTemplate"/>
            </ListSection>
        </ListView>
    </Window>
</Alloy>

контролер:

var items = [];

_.map(_.first(activities), function(element, key) {

    if (moment(new Date(key)).isValid()) {

        _.each(element, function(item, key) {
            items.push({
                fund: {
                    text: item.fund
                },
                amount: {
                    text: item.amount
                },
                units: {
                    text: item.units
                },
                source: {
                    text: item.source
                },
                unitValue: {
                    text: item.unitValue
                }
            });

        });
    }

});
$.activityList.sections[0].setItems(items);

Важното за мен е, че нямах нужда от properties:{} родител. Това ме обърка. Сега, когато имах данни в изгледа, просто трябваше да ги стилизирам с TSS файла.

person Mike S.    schedule 01.02.2016