Javascript 如何将对象转换为数组并在sencha中将值设置为selectfield

Javascript 如何将对象转换为数组并在sencha中将值设置为selectfield,javascript,sencha-touch,sencha-touch-2,Javascript,Sencha Touch,Sencha Touch 2,实际上,我从服务器获取国家:英格兰,那么如何设置英格兰的selectfield。我无法在“选择”字段中设置 在其他文本领域,我是这样管理的 Ext.getCmp('email').setValue(email); 但为什么不在selectfield中工作? 我对森查很有兴趣。现在我想转换数组 var testcountry= Ext.create('Test.store.CountryList'); console.log("Length of Country==="+testcountry

实际上,我从服务器获取国家:英格兰,那么如何设置英格兰的selectfield。我无法在“选择”字段中设置

在其他文本领域,我是这样管理的

Ext.getCmp('email').setValue(email);
但为什么不在selectfield中工作?

我对森查很有兴趣。现在我想转换数组

var testcountry=  Ext.create('Test.store.CountryList');
console.log("Length of Country==="+testcountry.getCount());
console.log("Country==="+testcountry);

for (var i = 0 ; i < testcountry.getCount() ; i ++){
    console.log("Country Value--"+testcountry.getAt(i).data.country);
}
店内:

Ext.define('Test.store.countryList', {
    extend: 'Ext.data.Store',

    config: {
    storeId: 'countryList',
    model: 'Test.model.countryList',
    data: [
    { text: ''},
    { text: 'Japan'},
    { text: 'India'},
    { text: 'Spain'},
    { text: 'Australia'},
    { text: 'Sudan'},
    { text: 'Brazil'},
    { text: 'Mexico'},
    { text: 'England'},
    { text: 'Chaina'},
   ]
}
});
在这样的控制台中:

Length of Country===9 
Country===[object Object] 
Country Value--undefined 
Country Value--undefined 
Country Value--undefined 
Country Value--undefined 
Country Value--undefined 
Country Value--undefined 
Country Value--undefined 
Country Value--undefined 
for (var i = 0 ; i < testcountry.getCount() ; i ++){
    console.log("Country Value--"+testcountry.getAt(i).getData().text);
}
{
                        xtype: 'selectfield',
                        placeHolder: 'Select Country',
                        store: 'countryList'
                    } 

如何打印所有国家/地区。

您的For循环片段应该如下所示:

Length of Country===9 
Country===[object Object] 
Country Value--undefined 
Country Value--undefined 
Country Value--undefined 
Country Value--undefined 
Country Value--undefined 
Country Value--undefined 
Country Value--undefined 
Country Value--undefined 
for (var i = 0 ; i < testcountry.getCount() ; i ++){
    console.log("Country Value--"+testcountry.getAt(i).getData().text);
}
{
                        xtype: 'selectfield',
                        placeHolder: 'Select Country',
                        store: 'countryList'
                    } 

谢谢你,现在,如何把选定的国家,如英国在selectfield。我不知道如何在选择字段中设置英格兰。创建一个选择字段,然后将存储设置为该选择字段。如果您使用的是Sencha Architect,只需拖动选择字段-->转到配置面板-->选择存储属性-->选择存储名称(在您的情况下,它应该是countryList)。查看更新后的答案。张贴selectfield代码