在JavaScript中获取json对象的键[duplicate](get keys of json-object in JavaScript [duplicate])
这个问题已经在这里有一个答案:
- 获取JavaScript对象密钥列表 11的答案
我在JavaScript中有一个json对象,我想在其中获取使用的键。 我的JavaScript代码如下所示:
var jsonData = [{"person":"me","age":"30"},{"person":"you","age":"25"}];
我想要一个循环,提醒我的“人”和“年龄”,这是json-Array中第一个对象的关键。
This question already has an answer here:
- Getting JavaScript object key list 15 answers
I have a json-object in JavaScript and I want to get the used keys in it. My JavaScript-Code looks like this:
var jsonData = [{"person":"me","age":"30"},{"person":"you","age":"25"}];
And I want a loop that alerts me 'person' and 'age', which are the keys of the first object in the json-Array.
原文:https://stackoverflow.com/questions/8430336
更新时间:2023-06-13 15:06
最满意答案
正如我所评论的,我写这个答案可能会帮助某人。这段代码只会在X轴上移动视图
@Override public boolean onTouch(View v, MotionEvent event) { switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: dX = v.getX() - event.getRawX(); dY = v.getY() - event.getRawY(); lastAction = MotionEvent.ACTION_DOWN; break; case MotionEvent.ACTION_MOVE: //remove this v.setY() line v.setX(event.getRawX() + dX); lastAction = MotionEvent.ACTION_MOVE; break; case MotionEvent.ACTION_UP: if (lastAction == MotionEvent.ACTION_DOWN) Toast.makeText(MainActivity.this, "Clicked!", Toast.LENGTH_SHORT).show(); break; default: return false; } return true; }
Finally this problem is resolved by making some changes in my code.Hope this will help someone achieving this effect.
@Override public boolean onTouch(View v, MotionEvent event) { switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: dx = v.getX() - event.getRawX(); dy = v.getY() - event.getRawY(); ball_dx = ball.getX(); lastAction = MotionEvent.ACTION_DOWN; break; case MotionEvent.ACTION_MOVE: // ball.setY(event.getRawY() + dy); if ((event.getRawX() + dx + ball_dx) < screenwidth - 80 && (event.getRawX() + dx + ball_dx) > 10) ball.setX(event.getRawX() + dx + ball_dx); lastAction = MotionEvent.ACTION_MOVE; break; case MotionEvent.ACTION_UP: if (lastAction == MotionEvent.ACTION_DOWN) Toast.makeText(MainActivity.this, "Clicked!", Toast.LENGTH_SHORT).show(); break; default: return false; } return true; }
相关问答
更多-
问题是你的线性冲动很强。 您可以使用Mario项目对此进行测试,如果增加冲动,您也会陷入墙壁。 要解决这个问题,要么降低冲量,降低摩擦力(但是你可能需要停止马里奥的代码)或者不是应用线性冲动,而是应用火炬并使用圆形形状让玩家“滚动”。 这些解决方案都不是完美的,但您可以尝试看看哪一种最适合您。 The problem is that your linear impulse is to strong. You can test this with the Mario project, if you incre ...
-
正如我所评论的,我写这个答案可能会帮助某人。这段代码只会在X轴上移动视图 @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: dX = v.getX() - event.getRawX(); dY = v.getY() - event. ...
-
override func touchesMoved(touches: Set
, withEvent event: UIEvent?){ let touch = touches.anyObject() as UITouch! let touchLocation = touch.locationInNode(self) let previousLocation = touch.previousLocationInNode(self) ... -
触摸我的夹具失败了(Touching my fixture fails)[2024-01-11]
好的,这是现在正在工作,但我相信我会有另外一个问题。 当我在上面运行时,我创建了一个相当小的动态盒子,这样物品就堆积在地上,相互重叠。 dynamicBox.SetAsBox(.25f,.25f) 这是原因。 当我把它打开到更大的东西时,说: dynamicBox.SetAsBox((spriteSize.width / PTM_RATIO)/ 4,(spriteSize.height / PTM_RATIO)/ 4); 然后,通过上述代码可以触摸身体。 (所以我的问题需要重新制定,因为我确实希望物体堆积起 ... -
您可能会收到该错误,因为您无法从树中的任何节点访问该视图。 您可以将其称为场景!.view或您在场景中处理手势,如果您想要保持简单,这是更可取的。 我试了一下,想出了这个基本场景: import SpriteKit class GameScene: SKScene { var shape:SKNode! override func didMoveToView(view: SKView) { //creates the shape to be moved ...
-
因此,您希望用户能够沿着弯曲路径在关键帧动画的中间触摸图像,并将其拖动到其他位置? 那时你想要发生什么动画? 你有多重挑战。 首先是在关键帧动画处于“飞行中”时检测对象上的触摸。 要做到这一点,你想使用父视图的图层的表示层的hitTest方法。 一个图层的表示层表示在任何给定时刻图层的状态,包括动画。 一旦检测到视图上的触摸,就需要从表示层获取图像的当前位置,停止动画,然后接管基于touchesMoved / touchesDragged的动画。 我写了一个演示应用程序,演示如何检测沿着路径动画的对象的触摸 ...
-
为此,您需要将taoGesture与UISlider一起使用,因此首先在滑块对象中添加UITapGestureRecognizer ,然后在gestureRecognizer选择器的action方法中设置其值。 在视图中添加滑块后添加以下代码。 UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSliderTap:)]; [ ...
-
如何移动SurfaceView上的对象而不触及对象本身?(How to move an object on a SurfaceView without touching the object itself?)[2022-04-05]
为什么不在onTouchEvent回调中获取并存储先前的MotionEvent坐标,然后当onTouchEvent再次触发时(ACTION_DOWN之后的第一个ACTION_MOVE,然后为每个ACTION_MOVE回调再触发)计算出值之间的偏移/差异,然后得到你自己的myPoint坐标并添加对当前值的偏移量。 这样你只能通过位置偏移来移动myPoint对象,而不是实际的坐标。 此代码未经过测试,我没有使用IDE,但是这样: private float oldX; private float oldY; ... -
在iOS中 - 在滚动视图中触摸文本字段时,视图无法滚动(In iOS - When touching a text field in a scroll view the view can not scroll)[2022-02-26]
对于已添加到文本字段的UIScrollView ,请尝试将delaysContentTouches属性设置为YES 。 这应该允许您在触摸时滚动,然后在文本字段中拖动。 Try setting the delaysContentTouches property to YES for the UIScrollView to which you have added to text field. This should allow you to scroll if you touch and then drag ... -
触摸UIScrollview?(Touching in UIScrollview?)[2023-08-13]
如果启用了UIScrollView中的滚动,则touchMoved事件不会传播到滚动视图内容。 如何解决方法取决于您想实现的目标。 在我的应用程序中,我只需要在UIScrollView拖动一个对象,并在contentView触摸处理程序中做了以下操作: 在touchesBegan:事件中,我检查了是否挖掘了要拖动的对象。 如果是 - 则在UIScrollView中禁用滚动 然后当滚动被禁用时,我的内容视图开始接收touchesMoved事件,我可以在那里“拖动”我的对象。 在touchesEnded:我重新 ...