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 8030739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:52:00+00:00 2026-06-05T00:52:00+00:00

I have a template: <script type=text/template id=action-template-item> <span data-layer=<%= target%> data-uuid=<%= uuid%>>delete</span> </script> I

  • 0

I have a template:

<script type="text/template" id="action-template-item">
    <span data-layer="<%= target%>" data-uuid="<%= uuid%>">delete</span>
</script>

I render the template in a view

    window.ActionView = Backbone.View.extend({
          template: $("#action-template-item").html(),
          initialize: function () {
                this.render();
          },
          render: function () {
              var tmpl = _.template(this.template);
              console.log(this.model);//model have "target"
              this.$el.html(tmpl(this.model));
              return this;
          }

    });

the template have only two property from model data,

before it render, I use console to check if the model have target value, the answer is positive,just like the comment above,

my model data is just like:

{
   target: "xxx-xxx-xxx",
   uuid: "xxx-xxx-xx"
}

but the firebug tell me "target is not defined"

What happened?What’s wrong with my code ?

  • 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-05T00:52:01+00:00Added an answer on June 5, 2026 at 12:52 am

    Your models probably look something like this:

    var M = Backbone.Model.extend({});
    var m = new M({
       target: "xxx-xxx-xxx",
       uuid: "xxx-xxx-xx"
    });
    

    Demo (open the console and you’ll see your error): http://jsfiddle.net/ambiguous/Rnd6k/

    So when you say

    //model have "target"
    

    you probably mean that this.model.attributes.target exists. Backbone model attributes and JavaScript object properties are not the same thing, the Underscore templates will be looking for object properties, they don’t know anything about Backbone model attributes.

    The usual approach is to serialize your model using toJSON when you want to render a view:

    render: function () {
        var tmpl = _.template(this.template);
        this.$el.html(tmpl(this.model.toJSON()));
        return this;
    }
    

    Demo: http://jsfiddle.net/ambiguous/Rnd6k/

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

Sidebar

Related Questions

I have the following KnockoutJS template (render with jquery.tmpl): <script id=contactsTemplate type=text/html> <li data-bind=click:
i have a script handlebar.. <script id=ownerItem data-template-name='ownerItem' type=text/x-handlebars> {{value.UserName}} &nbsp;<button {{action remove on=click}}>Remove</button>
I have a knockout template like this: <script type=text/html id=list> <ul data-bind=foreach: items> <li
I have a template like script type: text/template, id: list-template, ''' <div class=display> <div
I have follwing JSON: {mykey:[{name:Jak,interests:movies}]} and following opensocial app code: <script type=text/os-template require=mykey> <ul>
Is there no way to have an inline script within a Handlebars template? <script
Hallo I have this script: <? require(lib2/config.inc.php); require(lib2/tpl.class.php); require(lib2/db.class.php); require(lib2/um.class.php); $tpl = new template(templates,
I have a batch file containing a python script using the Output template> %(NAME)s
I have template like this: {% for a in As%} <div>blah--blah--</div> <input type=hidden name=doSomeThingTarget
I'm attempting to select all <script type=text/html> tags in a page. I use <script>

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.