我有以下对象,我试图从token
UserEmail
和Details
var obj = {
"id": null,
"firstName": null,
"lastName": null,
"createdAt": "2016-10-05T18:16:07.000Z",
"updatedAt": "2016-10-05T18:16:07.000Z",
"Details":
{
"id": 1,
"token": null,
"deviceId": null,
"code": 12345678,
"verified": null,
"createdAt": "2016-10-05T18:16:07.000Z",
"updatedAt": "2016-10-05T18:16:07.000Z",
"UserEmail": "joe@example.com"
}
}
我尝试了这个,但我得到了一个空白?
_.pick(_.pick(obj, 'Details'), 'code', 'UserEmail');
答案 0 :(得分:1)
您的内部pick
会返回一个带有Details
键的对象,然后您必须访问该对象。相反,做一些像:
_.pick(obj['Details'], 'code', 'UserEmail')
答案 1 :(得分:1)
_.pick(obj.Details, 'code', 'UserEmail')
答案 2 :(得分:0)
如果您在对象中严格设置了详细信息键,那么我会看到以下方式:
class PersonListAdapter(realm: Realm) :
RealmExpandableListAdapter<String, Person>(
itemGroupsProvider = { person -> arrayOf(person.group, null) },
groupsProvider = { people -> people.map { it.group } },
adapterData = realm.where(Person::class.java)
.findAllSortedAsync("lastName", Sort.ASCENDING, "firstName", Sort.ASCENDING)) {
override fun getGroupId(groupPosition: Int) = getGroup(groupPosition).id
override fun getChildId(groupPosition: Int, childPosition: Int) = getChild(groupPosition, childPosition).id
override fun hasStableIds() = true
override fun getGroupView(groupPosition: Int, isExpanded: Boolean, convertView: View?, parent: ViewGroup?): View {
// ... Item View here ...
}
override fun getChildView(groupPosition: Int, childPosition: Int, isLastChild: Boolean,
convertView: View?, parent: ViewGroup?): View {
// ... Group View here ...
}
override fun isChildSelectable(groupPosition: Int, childPosition: Int) = true
}