के साथ रनटाइम पर गतिशील रूप से एक दृश्य चुनना मैं विभिन्न प्रकार के मॉडल के साथ एक समयरेखा प्रदर्शित करने के लिए एम्बर, एम्बर डेटा और हैंडलबार्स का उपयोग कर रहा हूं। मेरा वर्तमान कार्यान्वयन, हालांकि ठीक से काम कर रहा है, ऐसा लगता है कि इसे एक सम्मेलन और सहायक के साथ काफी सुधार किया जा सकता है। हालांकि, मैं यह नहीं समझ सकता कि पहले से परिभाषित टेम्पलेट का उपयोग कैसे किया जाए।एम्बर + हैंडलबार्स
यह है कि मैं क्या है:
{{#view App.AccountSelectedView contentBinding="App.selectedAccountController.everythingSorted"}}
{{#with content}}
<ol class="timeline">
{{#each this}}
{{#is constructor="App.Design"}}
... stuff about the design
{{/is}}
{{#is constructor="App.Order"}}
... stuff about the order
{{/is}}
{{#is constructor="App.Message"}}
... stuff about the message
{{/is}}
{{/each}}
</ol>
{{/with}}
{{/view}}
... एक सहायक के साथ-साथ ...
Handlebars.registerHelper('is', function(options) {
if (this.constructor == options.hash["constructor"]) {
return options.fn(this);
}
});
मैं नहीं बल्कि क्या रेंडर करने के लिए देखने यह पता लगाने की कुछ सम्मेलन पर भरोसा करेंगे। उदाहरण के लिए:
<script type="text/x-handlebars-template" data-model="App.Design" id="design-view">
... stuff about the design
</script>
<script type="text/x-handlebars-template" data-model="App.Order" id="order-view">
... stuff about the order
</script>
शायद डेटा मॉडल विशेषता निर्धारित करने के लिए कैसे एक वस्तु प्रदान की गई है इस्तेमाल किया जा सकता।
{{#view App.SelectedAccountView contentBinding="App.selectedAccountController.everythingSorted"}}
{{#with content}}
<ol class="timeline">
{{#each this}}
{{viewish this}}
{{/each}}
</ol>
{{/with}}
{{/view}}
ओह, मैं समझ नहीं एक सहायक से खाका तक पहुँच करने के लिए कैसे।
Handlebars.registerHelper('viewish', function(options) {
// Were I able to access the templates this question
// would be unnecessary.
// Handlebars.TEMPLATES is undefined...
});
इसके अलावा, क्या मुझे हैंडलबार्स के साथ कुछ करना है?