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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:00:52+00:00 2026-06-18T06:00:52+00:00

Person = Backbone.Model.extend( defaults: name: ‘Jony James’ age: 30 occupation: ‘developer’ validate: (attrs) ->

  • 0
Person = Backbone.Model.extend(
  defaults: 
    name: 'Jony James'
    age: 30
    occupation:  'developer'

  validate: (attrs) ->
    if attrs.age < 0
      return 'Age must be positive, stupid.'
    if not attrs.name
      return 'A person must have a name! fool.'

  work: ->
    @get('name') + " is working." 
    )

PersonView = Backbone.View.extend({
    tagName: 'li'

    #template: _.template($('#personTemplate').html())
    template: "#personTemplate"

    initialize: ->
      @render()

    render: ->
      template = _.template($(@template))
      @$el.html(template)

    })

person = new Person
personView = new PersonView( model: person)
$(document.body).append personView.el

On my index.html

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title></title>
 </head>
 <body>
  <script id="personTemplate" type="text/template">
   <strong><%= name %></strong> (<%= age %>) - <%= occupation %> 
  </script>
  <script src="js/underscore.js"></script>
  <script src="js/jquery.js"></script>
  <script src="js/backbone.js"></script>
  <script src="js/main.js"></script>
 </body>
</html>

With template: _.template($('#personTemplate').html()) and @$el.html(@template(@model.toJSON())) is working fine.

but with current version of main.js I get this error in google chrome console:

Uncaught TypeError: Object [object Object] has no method 'replace'

Where is the error?

Thank you!

  • 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-18T06:00:54+00:00Added an answer on June 18, 2026 at 6:00 am

    The error is in the template function. Try passing the html instead of a jQuery object:

    template = _.template($(@template).html(), @model.toJSON())

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

Sidebar

Related Questions

I got this object Person = Backbone.Model.extend({ defaults: { name: 'Fetus', age: 0, children:
Person = Backbone.Model.extend({ defaults: { name: 'Fetus', age: 0, children: [] }, initialize: function(){
I have created an object: var Person = Backbone.Model.extend({ defaults: { 'name': '', 'age':
Basically, I'm trying to do something like this: Person = Backbone.Model.extend({ validate: { ...
The native javascript: var Person; Person = Backbone.Model.extend({}); This code is working fine if
I have a model named person: var person = Backbone.Model.extend({ initialize: function(){ console.log('cool'); },
If there is a Backbone Model called Person , which has properties firstName ,
cookie[person][name], cookie[person][id], cookie[person][age] How to make the cookie like above?
class Person(models.Model): name=models.CharField(max_length=30) .... followers=models.ManyToManyField(Person,blank=True, null=True) above is wrong because Person model could not
class Person(models.Model): name = models.CharField(max_length=100) class Entry(models.Model): text = models.CharField(max_length=100) person = models.ManyToManyField(Person, blank=True,

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.