Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7944765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:39:03+00:00 2026-06-04T00:39:03+00:00

Update the key issue here is an impedance mismatch between the ruby objects and

  • 0

Update the key issue here is an impedance mismatch between the ruby objects and associated methods we have now (handled in erb templates) and pure viewModels in JSON which we can feed to KnockoutJs etc. I’ll create KO-friendly viewModels w/all of the needed info for this area of the product and change other areas to use KO opportunistically…

I’m new to KnockoutJs. I have my viewModel set up and can display values using the ‘comment form’foreach like this

<!-- ko foreach: filteredProducts -->
  <span>id:</span>
   <span data-bind="text: id"></span>
   (...)
   <br/>
<!-- /ko -->

But what I need to do is reference one of the array entry values inside my foreach like this

<script> current_id = $data.id </script>

So that I can use the Id via ERB to call a Ruby function. But $data is not visible to script here.

The viewModel is visible but similar problem: visibility of $index (another KnockoutJs context variable for foreach) in script.

Ideas welcome – Michael

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:39:06+00:00Added an answer on June 4, 2026 at 12:39 am

    The answer is that you can’t and shouldn’t. You can’t reference $index from within an embedded script. And you shouldn’t embed a script in a Knockout foreach block; you will likely not like the result.

    Use bindings to interact between your view model (javascript) and your view (html). Use a custom binding if you need to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question here: MySQL: INSERT IGNORE or ON DUPLICATE KEY UPDATE with checking multiple
We have a legacy ASP.NET site which uses the encryption methods here: http://www.codekeep.net/snippets/af1cd375-059a-4175-93d7-25eea2c5c660.aspx When
i have this issue : Cannot add or update a child row: a foreign
Is it possible to INSERT...ON DUPLICATE KEY UPDATE into a table on the current
I need to update the primary key for a record but it's also the
I'm trying to update one value of a compound primary key from within the
How do I update a value that is referencing a foreign key. Lets say
What's the syntax for an Update query for a table without a primary key?
I'm trying to have a value ( key ) that updates to correspond with
Update In the wiki spirit of StackOverflow, here's an update: I spiked Joe White's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.