Initial value in uihtml + Javascript implementation of text input
이전 댓글 표시
Since I got extremely helpful input on a previous question on this same general theme:
I thought I'd turn to you amazing people again.
In the attached .mlapp and .html files, the app simply asks for input in the top box and echos whatever is entered there in the bottom box. Nice and simple.
What I'd like to do is have an initial value appear in this box, sent over from MATLAB. In this code, I am trying two things out:
1) I try entering one string in the startupFcn, line 17
2) I try entering another string in the initial definition of the uihtml widget, line 53.
Neither string appears when the app is run.
When input is received in the app and is recorded in the bottom box, it simply echos to the screen (when run inside MATLAB) the state of the "event" variable. That shows that app.HTML.Data was correctly set in startupFcn, line 17, but that value is not being sent over to the Javascript or not triggering the DataChanged listener in the Javascript code.
The process of updating the text that appears in the upper box, using app.HTML.Data = ... works just fine elsewhere in the MATLAB code, like in line 29.
So it seems that a listener, either on the MATLAB or on the Javascript side, is not up and running when the app's startupFcn executes. Is there a way to set an initial value in the uihtml text edit box in the startupFcn, or at least before the app has started and is waiting for user input?
댓글 수: 3
Antonio Hortal
2021년 10월 13일
Hey David! I am using Matlab 2021a, and when I run your app I can see the 'startupFcn test!' being displayed on the UIHTML input. If I remove the sartup function I also see the initial value fo the Data property (line 53).
I can't tell you for sure, but it might be that the 'setup' function in your .html file has not yet been executed when you set the Data property. You can check this matlab article that says that:
The setup function is called when one of these events happens:
- The HTML UI component is created in the figure and the content has fully loaded.
Have you tried using 'drawnow' commands before setting the Data property in the startup function? That will force the html content to load
function startupFcn(app)
drawnow;
app.HTML.Data = 'startupFcn test!';
end
David Aronstein
2021년 10월 13일
편집: David Aronstein
2021년 10월 13일
David Aronstein
2021년 10월 13일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Scripts에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!