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

  • Home
  • SEARCH
  • 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 8858451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:49:56+00:00 2026-06-14T14:49:56+00:00

I know this is not how you are supposed to do this but we

  • 0

I know this is not how you are supposed to do this but we have a legacy jQuery app and there has been some discussion of moving it to backbone. One idiom that would be appealing is something like this:

<script type="text/html" id="mi_form_template">
  the data-item-id is the value we are interested in!!!
 <button id="item" data-item-id='23'>here is item</button>
  </script>

I know that you are not supposed to store information like this in the DOM with backbone. But want to be able to anticipate the discussion about this.

Could I acces the item-id like this?

ItemsRouter = Backbone.Router.extend({
    routes: {
      "new": "newProduct",
      "": "index"
    },
    newProduct: function() {
      alert('here is newProduct');
      var item_id=$(this).data('item-id'); // <- can we do this???
      new ItemFormView( {model: new Item()});
    },
    ind ...

From preliminary tests, this won’t work – it looks like the reference to this isn’t working. Is this or something like this possible?

thx in advance

  • 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-14T14:49:57+00:00Added an answer on June 14, 2026 at 2:49 pm

    Normally you’d access data attributes through a view (not a router) with something like this:

    events: {
        'click #item': 'newProduct'
    },
    newProduct: function(ev) {
        var item_id = $(ev.target).data('item-id');
        // And now do whatever makes sense, possibly even trigger
        // a route that contains `item_id`.
    }
    

    A route handler doesn’t know what triggered it, it just knows that it is supposed to handle a particular URL pattern. If you wanted to use a router for this sort of thing then you’d want a link:

    <a href="/new/23">...</a>
    

    and then in the router:

    routes: {
        'new/:item_id': 'newProduct'
    },
    newProduct: function(item_id) {
        // Do things with item_id
    }
    

    So you can still use data attributes (which is okay with Backbone BTW) but you’d probably be accessing them in a view’s event handlers rather than in a router.

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

Sidebar

Related Questions

I know this is not the only question out there, but I still couldn't
I know this is not programming related, but I have a scenario. Each video
Ok, I know this has been asked a thousand times before, but no conclusive
I know this type of question has been asked a lot, but I really
Yes, I know I'm not supposed to do this. But the configuration file in
I know this has been a hot topic over the time... but I can't
I have an app, which is not supposed to be on the AppStore, but
I know this has been asked several times, but the problem is they bring
So I have this certain table. I know I'm not supposed to use table
Hey. I know this is not a 'refactor my code' site but I made

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.