Coder Social home page Coder Social logo

Use flx.create_element to create a label in the for loop, bind the onclick event, and dynamically transfer parameters. lambda fun error about flexx HOT 1 CLOSED

1751660300 avatar 1751660300 commented on August 15, 2024
Use flx.create_element to create a label in the for loop, bind the onclick event, and dynamically transfer parameters. lambda fun error

from flexx.

Comments (1)

almarklein avatar almarklein commented on August 15, 2024

This is a consequences of how closures work; the lambda loads the check_id from the outer scope, which will be left at whatever was its last value.

There are a few ways to fix this:

  • Classic closure solution: use a helper function to create a scope that holds check_id. E.g. a function create_my_element(check_id) that produces index_id.
  • Store self.checkd_fun on something like window.my_app_checkd_fun, and then "onclick": f"window.my_app_checkd_fun('{check_id}')". This works well when self is some sort of global object, but may get tricky if its not.
  • Use lambda e: self.checkd_fun(e), in checkd_fun check e.target to get the element. Store check_id on the element.

from flexx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.