我想获取与变量A中定义的条件“颜色”相关的值。
我正在获取对象的键,但是我想获取与条件“ Color”关联的值
home/icbosk/Desktop/WindowsApp1/watch.sln: warning : Don't know how to handle GlobalSection ExtensibilityGlobals, Ignoring.
}
例如: 我期待结果: 苹果 西红柿,草莓
答案 0 :(得分:1)
private void fetchData() {
List<Story> storyList = appPreferences.getFavouriteCardList();
List<YukulModel> yukulList = appPreferences.getFavouriteYukul();
if(storyList != null && storyList.size() > 0) {
showNoFavtText(false);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
recyclerView.setAdapter(new AdapterFavList1(this, storyList, yukulList, appPreferences));
}
if(yukulList != null && yukulList.size() > 0) {
showNoFavtText(false);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
recyclerView.setAdapter(new AdapterFavList1(this, storyList, yukulList, appPreferences));
}
}
作为条件时,您想要检索red
。
apple tomatoes, strawberry
。如果我的理解是正确的,那么该修改如何?请认为这只是几个答案之一。
如果您的脚本已修改,那么如何修改?
"apple", "tomatoes", "strawberry"
作为其他模式,这又如何呢?
function TestOBJ(){
var A = [
[['apple'],'red'],
[['tomatoes','strawberry'],'red'],
[['sky', 'deep sea'],'blue'],
[['frog'],'green']
]
var dataOBJ={};
for(var j=0;j<A.length;j++){
dataOBJ[j]= {
CONTENT: A[j][0],
COR: A[j][1]
}
}
Logger.log(dataOBJ);
const filtered = Object.keys(dataOBJ)
.reduce(function(ar, elemento) {
if (dataOBJ[elemento].COR == 'red') ar = ar.concat(dataOBJ[elemento].CONTENT);
return ar;
}, []);
Logger.log(filtered);
}
function TestOBJ(){
var A = [
[['apple'],'red'],
[['tomatoes','strawberry'],'red'],
[['sky', 'deep sea'],'blue'],
[['frog'],'green']
]
// I modified below script.
var color = "red";
var res = A.reduce(function(ar, e) {
if (e[1] === color) ar = ar.concat(e[0]);
return ar;
}, []);
Logger.log(res);
}
如果我误解了您的问题,而这不是您想要的结果,我深表歉意。