Comments (9)
Did you install the Magic Helpers properly? Check the browser console for any errors.
Can you build your demo on CodePen? (Maybe easiest to just fork a codepen in our demos)
FYI Alpine V3 will make the $parent
helper necessary (although it should still work, maybe)
from alpine-magic-helpers.
@KevinBatdorf thanks for quick reply, just came back but been working on this for a while so nice to have somebody to bounce ideas of.
Did you install the Magic Helpers properly?
I think so because i can run both demos you have in code pen they run fine right next to my non working code getting data from the fetched for loop data. That said this is what I have to load it (running this is a serverless environment:
<link
href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
rel="stylesheet"
/>
<script
src="https://cdn.jsdelivr.net/gh/kevinbatdorf/alpine-magic-helpers@latest/dist/interval.js"
defer
></script>
<script
src="https://cdn.jsdelivr.net/gh/alpine-collective/[email protected]/dist/component.min.js"
defer
></script>
<script
src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js"
defer
></script>
Can you build your demo on CodePen?
https://codepen.io/storegear/pen/GRrPvdv
THanks
from alpine-magic-helpers.
In that codepen, you're missing the component helper script. Seems to work after adding it?
from alpine-magic-helpers.
Item is not a property of the parent scope, it's just a variable generated on the fly during the loop and it doesn't get passed to the child component and so $parent is not aware of the current interaction, therefore $parent.item
can't work.
The only functional hack that can help you achieve that is to define the component as the root child of your loop and to use $el.__x_for.item to access the element. See: https://codepen.io/SimoTod/pen/PoWXaxL
from alpine-magic-helpers.
Oh right. This is where that $loop
helper would be useful.
from alpine-magic-helpers.
@SimoTod @KevinBatdorf Appreciate the quick responses and explanation. I want to take it a little bit further if you don't mind.
In the app I am making, the json data array is not hard coded but instead being fetched in my init() returned data. Perhaps is there an additional layer of waiting or something to that effect that would be needed to access that data in the loop for this counter? I'm getting the error message:
Alpine Error: "TypeError: Cannot read property 'item' of undefined
@KevinBatdorf $loop helper, not seeing this listed, where is that coming from! Thanks guys.
from alpine-magic-helpers.
Hard to tell without seeing the code but it doesn't look related to your x-init. Make sure the component is the root child of the template tag (otherwise it won't work) and that you spell the property correctly (2 underscores before x)
from alpine-magic-helpers.
$loop helper, not seeing this listed, where is that coming from! Thanks guys.
Just something we discussed adding in the future. Maybe for an Alpine V3 release if it's something that will be useful there (quite possibly not).
from alpine-magic-helpers.
I dropped this into your code pen:
fetch('https://my-json-server.typicode.com/typicode/demo/posts')
.then(response => response.json())
.then(data => this.items = data);
With no issues...so i must be doing something wrong with the root child, the hunt begins :/ Thanks for your guy's help!
from alpine-magic-helpers.
Related Issues (20)
- $get and $post are not defined HOT 2
- autoIntervalTest in $interval doesn't resume/restart properly HOT 11
- Test failing with latest Alpine version HOT 3
- iterator not working in table? HOT 2
- $parent not working with x-for HOT 6
- Problem using $scroll with $watch
- Hi Support AlpineJS V3 alpine-collective..? HOT 16
- RFC: Adding a $select magic helper HOT 4
- Scroll not working when loaded from another livewire component HOT 3
- Seems like $scroll smooth is not smooth anymore? HOT 4
- Missing source of script tag in installation-guide? HOT 1
- scroll not working in alpine.js v3 HOT 1
- $scroll produces promise error HOT 2
- [Question] Finding unused translations HOT 1
- Fallback for missing translations HOT 4
- Installation suggestion is incorrect
- [V3] Installation suggestion incorrect? HOT 1
- Cannot install HOT 1
- Installing doesn't work in V3 – callback is not a function HOT 6
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 alpine-magic-helpers.