[英]Appcelerator / Titanium Alloy - how to manipulate a string before it gets added to the view
我有一个钛合金视图,该视图输出一个TableView
以及每个缩略图的图像。 这是通过将URL传递到ImageView
元素的image
属性中来实现的。 由于它是由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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.