2012-06-27 11 views
6

पर कॉल करें मेरे पास WorkoutExerciseRowView है जो ExerciseRowView बढ़ाता है। रेंडर फ़ंक्शंस बेहद समान हैं, WorkoutExerciseRowView को छोड़कर ExerciseRowView के रेंडर को कुछ पैरामीटर जोड़ना होगा। WorkoutExerciseRowView के रेंडर फ़ंक्शन के अंदर मैं ExerciseRowView का रेंडर फ़ंक्शन कैसे कॉल कर सकता हूं?बैकबोन: एक विस्तारित दृश्य के ओवरराइड रेंडर() फ़ंक्शन

var WorkoutExerciseRowView = ExerciseRowView.extend({  
    render : function() { 
     //return this.constructor.render({ // doesn't work 
     return this.render({ // doesn't work 
      workoutExercise : this.model, 
      exercise : this.model.get("exercise"), 
      workoutSection : this.model.get("section"), 
      isEditable : true, 
      number : this.number, 
      WorkoutExercise : WorkoutExercise, 
      WorkoutSection : WorkoutSection 
     }); 
    } 
}); 

धन्यवाद!

उत्तर

14
var WorkoutExerciseRowView = ExerciseRowView.extend({  
    render : function() { 
     return ExerciseRowView.prototype.render.call(this,{ 
      workoutExercise : this.model, 
      exercise : this.model.get("exercise"), 
      workoutSection : this.model.get("section"), 
      isEditable : true, 
      number : this.number, 
      WorkoutExercise : WorkoutExercise, 
      WorkoutSection : WorkoutSection 
     }); 
    } 
}); 

बैकबोन के प्रलेखन यहाँ से: सुपर पर http://backbonejs.org/#Model-extend

संक्षिप्त तरफ: जावास्क्रिप्ट सुपर कॉल करने के लिए एक आसान तरीका प्रदान नहीं करता है - एक ही नाम के समारोह प्रोटोटाइप श्रृंखला पर उच्च परिभाषित किया। आप सेट की तरह एक मुख्य कार्य ओवरराइड हैं, या बचाने के लिए, और आप चाहते पैरेंट ऑब्जेक्ट के कार्यान्वयन आह्वान करने के लिए, आप करना होगा स्पष्ट रूप से, इसे कहते इन पंक्तियों के साथ:

Backbone.Model.prototype.set.call(this, attributes, options);

7

आप चाहिए गुंजाइश यह (वर्तमान मॉडल) के लिए सेट

1
साथ ExerciseRowView से

ExerciseRowView.prototype.render.call(this) 

यह उपयोग करने के लिए समारोह प्रस्तुत करना कॉल करेंगे में सक्षम हो

+1

गीथब पर पोस्ट के अनुसार, __super__ का उपयोग नहीं किया जाना चाहिए। –

संबंधित मुद्दे