How to use a template with textboxes loaded with data passed from the calling template to ember.js

I am trying to create an addstudent template that can be rendered with data when the editstudent option is clicked from another template.

I don't want to create different templates for addStudentDetails and EditstudentDetails. how to create a single template for these two functions.

Can anyone help me with this?

+3


source to share


1 answer


I see a couple of ways to do this.

  • Dashboard template using conditionals . Then in your controller, you can control whether you want to edit or add. A good example of this tutorial for ember is for state control .

  • Or you can use Routes and Resources. Perhaps the parent resource is called Student, followed by routes called edit and add. But you said that you don't want to use different templates, so I guess you probably want to use # 1.

//inside your controller
App.StudentController = Ember.ObjectController.extend({
  editStudent: true // or false
});

      



<!-- handlebars template possibly called studentTemplate -->
{{#if editStudent}}
  <!-- code for editStudent -->
{{else}}
  <!-- code for addStudent -->
{{/if}}

      

Hope that answers your question.

+1


source







All Articles