选择时,我试图将一个项目置于水平 listView 中。我目前的策略是首先测量项目并滚动到视图中引用项目的 x 坐标。
目前,任何时候我按下一个项目都会ListView滚动到最后x: 538
有没有更简单的方法来实现这一点,同时保持代码无状态/功能?
const ItemScroll = (props) => {
const createItem = (obj, rowID) => {
const isCurrentlySelected = obj.id === props.currentSelectedID
function scrollToItem(_scrollViewItem, _scrollView) {
// measures the item coordinates
_scrollViewItem.measure((fx) => {
console.log('measured fx: ', fx)
const itemFX = fx;
// scrolls to coordinates
return _scrollView.scrollTo({ x: itemFX });
});
}
return (
<TouchableHighlight
ref={(scrollViewItem) => { _scrollViewItem = scrollViewItem; }}
isCurrentlySelected={isCurrentlySelected}
style={isCurrentlySelected ? styles.selectedItemContainerStyle : styles.itemContainerStyle}
key={rowID}
onPress={() => …Run Code Online (Sandbox Code Playgroud) 在iPhone模拟器开发者菜单将不会推出任何cmd + D或cmd + ctrl + z
我检查过的东西(无序):
cmd + r 工作正常watchman 4.7.0安装有brew install watchman(--HEAD需要libtoolize,其中brew更改为glibtoolize,因此./autogen找不到它)react-native start --clear-cache启动成功,react-native run-ios构建成功其他事宜
nw_connection_get_connected_socket_block_invoke 1262 Connection has no connected handler 无限期运行react-native run-ios 产出命令失败:/usr/libexec/PlistBuddy -c 打印:CFBundleIdentifier build/Build/Products/Debug-iphonesimulator/zelosApp.app/Info.plist 打印:条目,“:CFBundleIdentifier”,不存在命令失败:/usr/libexec/ PlistBuddy -c 打印:CFBundleIdentifier build/Build/Products/Debug-iphonesimulator/zelosApp.app/Info.plist 打印:条目,“:CFBundleIdentifier”,不存在
版本
如何在保留键名的同时将对象转换为对象数组?
// actual
obj = {
key1: null,
key2: "Nelly",
key3: [ "suit", "sweat" ]
}
// expected
arr = [
{ key2: "Nelly" },
{ key3: [ "suit", "sweat" ] }
]
Run Code Online (Sandbox Code Playgroud)
目前我的解决方案是......
var arr = Object.keys(obj).map(key => { if (obj[key]) return { key: obj[key] } });
Run Code Online (Sandbox Code Playgroud)
返回
arr = [
undefined,
{ key: "Nelly" },
{ key: [ "suit", "sweat" ] }
]
Run Code Online (Sandbox Code Playgroud)