当我单击React JS中的一个按钮时,有没有办法访问DIV并在其中进行另一个DIV?

发布于 2025-01-17 14:42:50 字数 2485 浏览 0 评论 0 原文

我正在尝试模仿香草JS中主要使用的内容,即 document.createelement(...)
我一直在尝试与Webrtc和Kurento合作,这使我进入了这个永无止境的混乱循环。我正在尝试遵循他们的文档,该文档属于纯JavaScript,以备多对多用例,但我必须在React中实现它。

https://doc-kurento.readthedocs.io/en/stable/tutorials/java/tutorial-groupcall.html

任何帮助都会很好。 我什

至尝试复制和粘贴代码并将其作为最后的手段将其连接起来,但这使情况变得更糟。

编辑 -

意思是在参与者中说的。

function Participant(name) {
this.name = name;
var container = document.createElement('div');
container.className = isPresentMainParticipant() ? 
PARTICIPANT_CLASS : PARTICIPANT_MAIN_CLASS;
container.id = name;
var span = document.createElement('span');
var video = document.createElement('video');
var rtcPeer;

container.appendChild(video);
container.appendChild(span);
container.onclick = switchContainerClass;
document.getElementById('participants').appendChild(container);

span.appendChild(document.createTextNode(name));

我很抱歉没有之前提供足够的详细信息,我的 我将把文件链接到具有JS文件和index.html

https://github.com/kurento/kurento/kurento-tutorial-java/tree/master/master/kurento-group-cloup-call/src/src/main/resources /静态

因此,在此特定功能中,他们使用 - var container = document.createelement('div');

它在HTML文件中创建DIV内部的DIV

<div id="room" style="display: none;">
            <h2 id="room-header"></h2>
             <div id="participants">
               (Creates a div here and video is rendered here)
             </div>
            <input type="button" id="button-leave" 
                onmouseup="leaveRoom();"
                value="Leave room">
        </div>

-conferenceroom.js中调用了

var participant = new Participant(name);

github的第105行,在“现有参与者”功能下的第105行。

简而言之,

我只想知道,在单击React中的按钮时,在单击一个按钮时,使用不同的类名称或标签名等添加新的Divs的更好方法是什么。

我找不到使用Kurento P.S在React JS中进行项目的任何人进行的项目

- 我对Stackoverflow非常新,我也在学习问问题,对此表示抱歉,为头痛感到抱歉:(

I am trying to mimic what is mostly used in vanilla JS which is document.createElement(...)
I have been trying to work with WebRTC and kurento which has brought me to this never ending loop of confusion. I am trying to follow their documentation which is in pure JavaScript for a many-to-many use case, but I have to implement it in react.

https://github.com/Kurento/kurento-tutorial-java/tree/master/kurento-group-call

https://doc-kurento.readthedocs.io/en/stable/tutorials/java/tutorial-groupcall.html

Any help will be great. There is not much about this topic on the internet

I have tried to even copy and paste the code and connect it as a last resort, but that has made things worse.

EDIT --

I am sorry for not providing enough details earlier , what I meant to say was in Participant.js (which is the front end and completely written in Javascript) there is a function which is as follows-

function Participant(name) {
this.name = name;
var container = document.createElement('div');
container.className = isPresentMainParticipant() ? 
PARTICIPANT_CLASS : PARTICIPANT_MAIN_CLASS;
container.id = name;
var span = document.createElement('span');
var video = document.createElement('video');
var rtcPeer;

container.appendChild(video);
container.appendChild(span);
container.onclick = switchContainerClass;
document.getElementById('participants').appendChild(container);

span.appendChild(document.createTextNode(name));

and it goes on like that I will link the file to the exact path to the front end which has the js files and the index.html

https://github.com/Kurento/kurento-tutorial-java/tree/master/kurento-group-call/src/main/resources/static

So in this particular function they use -
var container = document.createElement('div');

which creates a div inside a div in the html file -

<div id="room" style="display: none;">
            <h2 id="room-header"></h2>
             <div id="participants">
               (Creates a div here and video is rendered here)
             </div>
            <input type="button" id="button-leave" 
                onmouseup="leaveRoom();"
                value="Leave room">
        </div>

The Particpant function is called in conferenceroom.js --

var participant = new Participant(name);

line 105 on github under 'existingParticipants' function.

TL;DR

In short I just want to know what is the better way to approach manipulating a dom element and adding new divs with different classnames or tagnames etc on the click of a button in React.

I cannot find anyone who has done a project on a group call in React Js using Kurento

P.S - I am very new to stackoverflow , and I am learning to ask questions too, sorry for the headache :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

腹黑女流氓 2025-01-24 14:42:50

如果要在孩子内部创建相同的父组件,则可以使用递归调用。

function InnerDiv ({count=5}) {
  return (
    <div>
      <h5>This is a component</h5>
    {count>0?<InnerDiv count={count-1} />: null }
    </div>)
}

然后,当您将此组件添加到另一个组件(例如应用程序)中时,只需传递计数。

export default function App() {
  return (
    <div className="App">
      <InnerDiv count={4} />
    </div>
  );
}

If you want to create the same parent component inside the child, you can use recursive call.

function InnerDiv ({count=5}) {
  return (
    <div>
      <h5>This is a component</h5>
    {count>0?<InnerDiv count={count-1} />: null }
    </div>)
}

Then when you add this component in another component (Like App), just pass the count vairiable.

export default function App() {
  return (
    <div className="App">
      <InnerDiv count={4} />
    </div>
  );
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文