我创建了一个显示国家/地区列表的选择器,它运行正常。目前默认选择第一个国家/地区。我需要把它改成另一个国家。我该怎么做?
这是我创建的选择器
Picker {
id: picker
title: "Select your country"
expanded:true
verticalAlignment: VerticalAlignment.Fill
// A DataModel is used to populate the picker.
dataModel: XmlDataModel {
source: "Model/CountryCodes.xml"
}
// Picker items are set up similarly as to how its done in a ListView.
pickerItemComponents: [
PickerItemComponent {
type: "country"
content: Container {
background: Color.create("#9B59B6")
layout: DockLayout {
}
Label {
multiline: true
maxWidth: 1000
text: pickerItemData.name
verticalAlignment: VerticalAlignment.Center
horizontalAlignment: HorizontalAlignment.Center
textStyle {
base:SystemDefaults.TextStyles.BodyText
color: Color.White
fontSize: FontSize.PointValue
fontSizeValue: 10.0
fontWeight: FontWeight.Normal
}
}
}
}
]
onSelectedValueChanged: {
// These are the currently selected indexes.
var index0 = picker.selectedIndex(0);
var type = dataModel.data([0, picker.selectedIndex(0)]);
console.log("Selected index:"+index0);
countryCode.mainText="+"+type.phoneCode;
}
}
我的countrycodes.xml采用此格式
<model>
<column loop="false" colspan="3" >
<country code='af' phoneCode='93' name='Afghanistan' />
<country code='al' phoneCode='355' name='Albania' />
........all other countries.....
</column>
</model>
目前阿富汗的节目一直在挑选。
答案 0 :(得分:0)
我用过它,从设置中加载哪一个。这放在onCreationCompleted
picker.select(0, app.getValueFor("backImageID", 0));
,第二个元素是这样的
picker.select(1, app.getValueFor("fontColorID", 0));