等到Pyscript软件包满载,然后修改DOM

发布于 2025-02-10 09:54:19 字数 251 浏览 1 评论 0原文

我想等到Pyscript满足所有软件包,然后更改DOM上的元素。

我尝试使用window.addeventlistener('load',create_proxy(func))在Pyscript中。但无济于事,它不会执行该功能。我还尝试将事件侦听器'更改'添加到Pyscript修改的元素中。该元素用于使用面板软件包插入表。插入表之后,我想删除页面上的另一个元素。

任何帮助都赞赏

I want to wait until pyscript has fully loaded all packages and after that alter an element on the DOM.

I tried using window.addEventListener('load', create_proxy(func)) in pyscript. But to no avail, it does not execute the function. I also tried adding the event listener 'change' to the element that is being modified by pyscript. The element is used for inserting a table using the panel package. After the table is inserted I'd like to remove another element on the page.

Any help appreciated

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

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

发布评论

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

评论(2

眼眸里的快感 2025-02-17 09:54:19

基本方法是使用pyscript.write()。

<html>
    
    <head>
            
        <title>Pyscript - Test</title>
     
    <!-- Load required PyScript packages -->
        <link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
        <script defer src="https://pyscript.net/alpha/pyscript.js"onerror=scriptLoadFailure('pyscr ipt.js')></script>

<py-env>
- pandas
</py-env>

    </head>
    
<!-- ------------------------------------------------------------------- -->
    <body>
        
<py-script>
import pandas as pd
def do_it():
    df = pd.DataFrame([[12, 14, 10, 11, 1], [22, 24, 20, 21, 0]])
    pyscript.write('output', df)
    pyscript.write('msg', 'That should be it')
do_it()
</py-script>
        <header id="header_top">Pyscript - Test</header>
        <div id="main1">
            <div id="output">
                Testing div with id="output" 
            </div>
            <div id="msg"></div>
        </div>
    </body>
<!-- ------------------------------------------------------------------- -->
</html>

加载前客的内容时
Pyscript-测试
带有ID =“输出”的测试div

加载完成后,输出div中有PANDAS DF,并且具有ID =“ MSG”的单独div中的其他文本
“应该就是这样” 提示...

The basic way is to use pyscript.write().

<html>
    
    <head>
            
        <title>Pyscript - Test</title>
     
    <!-- Load required PyScript packages -->
        <link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
        <script defer src="https://pyscript.net/alpha/pyscript.js"onerror=scriptLoadFailure('pyscr ipt.js')></script>

<py-env>
- pandas
</py-env>

    </head>
    
<!-- ------------------------------------------------------------------- -->
    <body>
        
<py-script>
import pandas as pd
def do_it():
    df = pd.DataFrame([[12, 14, 10, 11, 1], [22, 24, 20, 21, 0]])
    pyscript.write('output', df)
    pyscript.write('msg', 'That should be it')
do_it()
</py-script>
        <header id="header_top">Pyscript - Test</header>
        <div id="main1">
            <div id="output">
                Testing div with id="output" 
            </div>
            <div id="msg"></div>
        </div>
    </body>
<!-- ------------------------------------------------------------------- -->
</html>

While loading the content of the paage is
Pyscript - Test
Testing div with id="output"

After loading has finished there is a pandas df in the output div and additional text in a separate div with id="msg"
"That should be it" Regards...
enter image description here

半城柳色半声笛 2025-02-17 09:54:19

加载任何Pyscript软件包之前,请在JS中运行此。

pyscriptLoaded = false

// Store the original console.log function
const originalConsoleLog = console.info;

// Override the console.log function with a custom one
console.info = function (message) {
  originalConsoleLog.apply(console, arguments); // Call the original console.log function

  if (message.includes('PyScript page fully initialized')) {
    pyscriptLoaded = true;
    console.log = originalConsoleLog;
  }
};

它拦截了控制台日志消息并查找何时强加了加载

Run this in JS before you load any of the pyscript packages.

pyscriptLoaded = false

// Store the original console.log function
const originalConsoleLog = console.info;

// Override the console.log function with a custom one
console.info = function (message) {
  originalConsoleLog.apply(console, arguments); // Call the original console.log function

  if (message.includes('PyScript page fully initialized')) {
    pyscriptLoaded = true;
    console.log = originalConsoleLog;
  }
};

It intercepts the console log messages and find when it has compelted loading

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文