我有一组像这样的对象:
[
0:'some value'
1:'some value'
3:'some value'
]
我想要的是一个很好的对象数组,没有用于editabale选择的键,如下所示:
[
{value: 1, text: 'Active'},
{value: 2, text: 'Blocked'},
{value: 3, text: 'Deleted'}
]
我试过循环和分配,但我得到了相同的结果。 我怎样才能实现这个阵列:
cities.push({value:value, text:value});
答案 0 :(得分:1)
你的初始'对象数组'没有意义......你的意思是那些是给定单个对象的属性吗?
如果是这样,你需要做的是使用for循环遍历对象属性,例如
protected void onResume(){
super.onResume();
int numLines = 100;
int numOfBottles = 99;
String line;
String lyrics= "Lyrics to 99 bottles of beer \n\n";
TextView textview = (TextView) findViewById(R.id.myTextView);
textview.setText(lyrics);
for(int i = numOfBottles;i >= 1;i--) {
if (numOfBottles >= 1) {
line = "Line " + numLines-i + ":\n";
textview.append(line + i + " bottles of beer on the wall," +
i + " bottles of beer, take one down, pass it around," +
i-1 + " bottles of beer on the wall.\n\n");
}
}
}