2014-02-14 17 views
1

我在鈦合金視圖它通過視頻列表循環集合中,像這樣:鈦合金過濾功能 - 如何訪問我迭代的觀點在

<View dataCollection="videos" dataFilter="recentlyAddedFilter"> 
    <ImageView image="{img}" width="200"> 
      <Label text="{title}"></Label> 
    </ImageView> 
</View> 

我有一個叫做recentlyAddedFilter過濾功能,在我的控制器定義,像這樣:

function recentlyAddedFilter(collection) { 
    return collection.where({title:'A title'}); 
} 

我要創建這個view組件的多個版本,所以我想過濾功能,能夠訪問每個單獨組件它適用於,就像我可以使用012一樣裏面的過濾功能。所以,如果我可以做這樣的事情會很好:

function recentlyAddedFilter(collection) { 
    theComponent.width = "200dp"; // change property on component that calls this function 
    return collection.where({title:'A title'}); 
} 

有沒有辦法可以做到這一點?

回答

2

而是使用dataTransform函數來添加用於構建視圖到JSON一個屬性,然後與添加的自定義屬性,多調用它的任何其它屬性。例如:

<View dataCollection="videos" dataFilter="recentlyAddedFilter" 
           dataTransform="recentlyAddedTransform"> 
    <!-- Pass the customWidth attribute that was added in the transform function --> 
    <ImageView image="{img}" width="{customWidth}"> 
      <Label text="{title}"></Label> 
    </ImageView> 
</View> 

所以您的控制器是這樣的:

// Takes a collection 
function recentlyAddedFilter(collection) { 
    return collection.where({title:'A title'}); 
} 

// Takes a model 
function recentlyAddedTransform(model) { 
    // Make sure to convert the model to JSON 
    var transform = model.toJSON(); 
    // Add a custom width attribute to the model 
    transform.customWidth = "200dp"; 
    return transform; 
} 

請記住,在你與一個單獨的模型工作dataTransform功能,但你正在返回JSON。