Git Product home page Git Product logo

Comments (9)

KevinBatdorf avatar KevinBatdorf commented on May 27, 2024

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.

mrbm avatar mrbm commented on May 27, 2024

@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.

KevinBatdorf avatar KevinBatdorf commented on May 27, 2024

In that codepen, you're missing the component helper script. Seems to work after adding it?

from alpine-magic-helpers.

SimoTod avatar SimoTod commented on May 27, 2024

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.

KevinBatdorf avatar KevinBatdorf commented on May 27, 2024

Oh right. This is where that $loop helper would be useful.

from alpine-magic-helpers.

mrbm avatar mrbm commented on May 27, 2024

@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.

SimoTod avatar SimoTod commented on May 27, 2024

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.

KevinBatdorf avatar KevinBatdorf commented on May 27, 2024

$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.

mrbm avatar mrbm commented on May 27, 2024

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)

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.