我有一个钛合金视图,该视图TableView
为每个视图输出一个图像缩略图。这是通过将URL传递到元素的image
属性中来实现的ImageView
。由于它是由Alloy集合填充的Alloy视图,因此可以为我处理数据循环:
<TableView id="brandsList" dataCollection="brands">
<TableViewRow brandID="{brand_id}">
<View class="vgroup">
<ImageView height="45" width="80" id="image" image="{image}" />
<Label id="name" text="{name}" />
</View>
</TableViewRow>
</TableView>
但是,我想在到达上面的视图之前稍微更改一下URL字符串。特别是我需要在URL的中间添加一些值,这些值会更改图像质量和大小。如何捕获此字符串的字符串值并进行更改?
从这段代码的外观看来,您正在进行数据绑定。您可以先转换数据,再将数据显示在视图中
http://docs.appcelerator.com/titanium/latest/#!/guide/Alloy_Data_Binding
<TableView id="brandsList" dataCollection="brands" dataTransform="transformFunction">
<TableViewRow brandID="{brand_id}">
<View class="vgroup">
<ImageView height="45" width="80" id="image" image="{image}" />
<Label id="name" text="{name}" />
</View>
</TableViewRow>
</TableView>
然后在代码中
function transformFunction(model) {
// Need to convert the model to a JSON object
var transform = model.toJSON();
transform.image = /* do someting to image url string */;
return transform;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句