Skip to content

Instantly share code, notes, and snippets.

@sebastienblanc
Created March 20, 2014 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastienblanc/9674210 to your computer and use it in GitHub Desktop.
Save sebastienblanc/9674210 to your computer and use it in GitHub Desktop.
bind: [{
to: { $ref: 'firstCollection' },
bindings: {
firstName: '.first-name',
lastName: '.last-name'
},
{to: { $ref: 'secondCollection' },
bindings: {
contractNumber: '.contractNumber',
lastName: '.last-name'
}
}]
@unscriptable
Copy link

Hey @sebastienblanc,

The bind facet only takes a single object, not an array.

This is really interesting. How can two collections be bound to the same element (the element matching ".last-name")? This seems like it would cause havoc, no?

It's certainly possible to have two collections bound into the same DOM fragment, but I would think you would want to bind to different elements (or element attributes) in that fragment. In this case, you need to use the bind facet on two different element-components. One could be a parent of the other.

-- John

@unscriptable
Copy link

If you show a little bit more of the wire spec, I might be able to give some more detailed help. :)

@sebastienblanc
Copy link
Author

This is what I would like to do

 conversationSectionView: {
        render: {
            template: { module: 'text!app/conversation/ConversationSection.html' }
        },
        insert: { after: 'controllerView' },
        bind: {
            to: { $ref: 'conversations' },
            bindings : {
                lastMessage: ".lastMessage"
            }
        },
        bind: {
            to: { $ref: 'contacts' },
            bindings : {
                displayName: ".displayName"
            }
        }
    },

@unscriptable
Copy link

    conversationSectionView: {
        render: {
            template: { module: 'text!app/conversation/ConversationSection.html' }
        },
        insert: { after: 'controllerView' },
        bind: {
            to: { $ref: 'conversations' },
            bindings : {
                lastMessage: ".lastMessage"
            }
        }
    },
    contactsSubsectionView: {
       // query for a child of conversationSectionView
        element: { $ref: '.some-class-of-a-child-element', at: { $ref: 'conversationSectionView' } },
        bind: {
            to: { $ref: 'contacts' },
            bindings : {
                displayName: ".displayName"
            }
        }
    }

@unscriptable
Copy link

oops, i goofed on this line. the "at" doesn't need another "$ref":

element: { $ref: '.some-class-of-a-child-element', at: 'conversationSectionView' },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment