shr*_*ans 1 javascript titanium appcelerator titanium-alloy
我有一个钛合金视图,它输出一个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>
Run Code Online (Sandbox Code Playgroud)
但是,在进入上面的视图之前,我想稍微更改一下这个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>
Run Code Online (Sandbox Code Playgroud)
然后在代码中
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;
}
Run Code Online (Sandbox Code Playgroud)