我的方法getUserInfo()返回Observable。如何改变我的observable内部的对象,当我使用我的方法时,getUserInfo()在我的observable中得到了我修改过的对象?
getUserInfo():Observable<UserInfo>
{
return this.Obser;
}
在这里,我将我的物体放在天文台内并覆盖它:
openDialog() {
let dialogRef = this.dialog.open(DialogOverviewExampleDialog);
dialogRef.afterClosed().subscribe(result => {
let subscription = this.UserService.getUserInfo().subscribe(
value => (value = result)
); this.name = result.firstName+" "+result.lastName; this.data = result;
});
}
}
答案 0 :(得分:0)
如何让我的observable内部的对象发生变化?
这完全 the map
operator的用途。如果您的observable使用fisrtName,lastName和age发出用户,则可以执行以下操作以获取其全名的可观察值:
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Robot robot = null;
try {
robot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
robot.mouseMove(350, 150);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.keyPress(KeyEvent.VK_T);
robot.keyRelease(KeyEvent.VK_T);
// Solution for different keyboard layouts (ALT values)
try {
alt(KeyEvent.VK_NUMPAD0, KeyEvent.VK_NUMPAD0, KeyEvent.VK_NUMPAD4, KeyEvent.VK_NUMPAD7);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
robot.keyPress(KeyEvent.VK_Q);
robot.keyRelease(KeyEvent.VK_Q);
}