-
-
Save ChuckJHardy/2910528 to your computer and use it in GitHub Desktop.
Dynamic partials in Batman.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div data-replace="item"> | |
PARTIAL 1: <span data-bind="item.name"></span> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div data-replace="item"> | |
PARTIAL 2: <span data-bind="item.name"></span> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class App.ItemsController extends App.ApplicationController | |
show: () -> | |
@render() | |
updatePartial: (node) -> | |
partial = $(node).val() || 'partial1' | |
v = new Batman.View | |
# This tells the View to use this file as its template | |
source: "items/_#{partial}" | |
# This feeds the controller's renderContext to the view. | |
context: @.get '_renderContext' | |
# If you want to use a string for the source instead of a filename, use this: | |
#html: "CUSTOM HTML: <div data-bind='item.name'></div>" | |
v.render() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Main View</p> | |
<a data-event-click="updatePartial" data-id="partial1">Partial 1</a> | | |
<a data-event-click="updatePartial" data-id="partial2">Partial 2</a> | |
<div data-yield="item"> | |
<div data-partial="items/_partial1"></div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment