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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:43:38+00:00 2026-06-04T07:43:38+00:00

I have the following problem… MyView which is connected to two views: TaskModel and

  • 0

I have the following problem…

MyView which is connected to two views: TaskModel and UserModel

TaskModel = {id: 1, taskName: "myTask", creatorName: "myName", creator_id: 2 },
UserModel = {id: 2, avatar: "someAvatar"}

The view should display

{{taskName}}, {{creatorName}}, {{someAvatar}}

As you can see the fetch of TaskModel and UserModel should be synchronized, because the userModel.fetch needs of taskModel.get("creator_id")

Which approach do you recommend me to display/handle the view and the two models?

  • 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-04T07:43:39+00:00Added an answer on June 4, 2026 at 7:43 am

    You could make the view smart enough to not render until it has everything it needs.

    Suppose you have a user and a task and you pass them both to the view’s constructor:

    initialize: function(user, task) {
        _.bindAll(this, 'render');
        this.user = user;
        this.task = task;
        this.user.on('change', this.render);
        this.task.on('change', this.render);
    }
    

    Now you have a view that has references to both the user and the task and is listening for "change" events on both. Then, the render method can ask the models if they have everything they’re supposed to have, for example:

    render: function() {
        if(this.user.has('name')
        && this.task.has('name')) {
            this.$el.append(this.template({
                task: this.task.toJSON(),
                user: this.user.toJSON()
            }));
        }
        return this;​​​​
    }
    

    So render will wait until both the this.user and this.task are fully loaded before it fills in the proper HTML; if it is called before its models have been loaded, then it renders nothing and returns an empty placeholder. This approach keeps all of the view’s logic nicely hidden away inside the view where it belongs and it easily generalizes.

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


    You could also use Underscore’s isEmpty (which is mixed into Backbone models) instead of checking a specific property:

    render: function() {
        if(!this.user.isEmpty()
        && !this.task.isEmpty()) {
            this.$el.append(this.template({
                task: this.task.toJSON(),
                user: this.user.toJSON()
            }));
        }
        return this;​​​​
    }
    

    That assumes that you don’t have any defaults of course.

    Demo: http://jsfiddle.net/ambiguous/4q07budc/

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

Sidebar

Related Questions

I have the following problem: I got a view with two text fields and
I have following problem: I have built a tabbar application with 4 tabs. I
I have following problem, Code: String a=Yeahh, I have no a idea what's happening
I have the following problem: I have a form in site/banen (currently local running
I have the following problem. I have three classes, A, B and C. A
I have the following problem: I implemented a managed mobile application for Windows Mobile
I have the following problem that the standard library doesn't solve well, and I'm
I have the following problem in a Database using Access 2007 as front end
I have the following problem. I have a table with a few hundred thousand
I have a following problem: I compiled my application on Linux Ubuntu 9.10 using

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.