Comments (5)
Good question. This has come up before and we made some code changes to support this use case. The problem is that the server is not keeping any state and the unique IDs reset back to 0
reset for each request. As a workaround, we allow the application code to provide a "widget ID prefix" which is just some string that is prefixed to the auto generated ID and this prefix can be used to keep widget IDs unique across requests (assuming the application code provides an appropriate prefix).
The widget ID prefix should be provided as part of the rendering "global" object as shown in the following sample code:
template.render({
$global: {
widgetIdPrefix: 'w' + Math.random()
}
},
function(err, html) {
});
Here is the related code that is used to generate unique IDs on the server: lib/uniqueId.js
Does that solve your problem?
from marko-widgets.
Yeah that should work. We'll give it a try.
Correcting the link you listed:
https://github.com/raptorjs/marko-widgets/blob/master/lib/uniqueId.js
from marko-widgets.
Please update this Github issue when verified.
I have updated the link. Thanks.
from marko-widgets.
ping. Did this solution work for you?
from marko-widgets.
Sorry, I didn't close this sooner. The suggested fix works great.
from marko-widgets.
Related Issues (20)
- Proposal: Marko Widgets with ES6 and inline Marko templates HOT 6
- Bubbling event listeners are attached too late HOT 1
- Listeners for event delegation do not work if `document.body` is not available HOT 1
- w- prefix HOT 1
- Add support for csp nonce HOT 1
- Add support for delaying widget destruction from an onBeforeDestroy handler HOT 2
- Macro tag doesn't play well with w-bind / widget
- Bug: w-onchange adds "|w0" for null input HOT 1
- No error message when `w-bind` is used and no `index.js` or `widget.js` is found
- Out parameter?
- w-for attribute not being removed HOT 1
- event-delegation.js:44 Uncaught TypeError: Cannot read property '__widget' of null HOT 1
- Proposal: Template as entry point for UI components HOT 6
- Getting the nested widget instance
- Declarative DOM event listeners broken for non-bubbling events on repeated elements HOT 1
- Make state property full reactively HOT 3
- Missing something with lasso and marko-widgets
- Calling A component in for loop . only trigering first element HOT 3
- Extra event handlers are getting added when noConflict js containing marko widgets is loaded
- Special unicode chars (\u2028 and \u2029) need to be escaped if within script tag
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from marko-widgets.