Skip to content

Commit

Permalink
* [jsfm] fix #1237, fix binding event bug of components which have re…
Browse files Browse the repository at this point in the history
…peat attribute
  • Loading branch information
zhangquan committed Sep 22, 2016
1 parent ec10e8d commit bfed029
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
3 changes: 2 additions & 1 deletion html5/default/vm/directive.js
Expand Up @@ -254,7 +254,8 @@ function bindEvents (vm, el, events) {
console.debug(`[JS Framework] The method "${handler}" is not defined.`)
}
}
setEvent(vm, el, key, handler)
const realVm = vm._realParent ? vm._realParent : vm
setEvent(realVm, el, key, handler)
}
}

Expand Down
56 changes: 55 additions & 1 deletion html5/test/unit/default/vm/events.js
Expand Up @@ -59,7 +59,6 @@ describe('bind and fire events', () => {

checkReady(vm, function () {
doc.close()

expect(doc.body.event.click).a('function')

const el = doc.body
Expand All @@ -79,6 +78,61 @@ describe('bind and fire events', () => {
})
})

it('context of event binding to element width repeat attribute', (done) => {
customComponentMap.foo = {
template: {
type: 'div',
id: 'container',
events: {
click: 'containerClick'
},
children: [
{
type: 'div',
id: 'items',
'repeat': function () { return this.items },
events: {
click: 'itemsClick'
},
children: [
{
type: 'div'
}
]
}
]
},
data: function () {
return {
items: [
{ name: 1 },
{ name: 2 }
]
}
},
methods: {
containerClick: function () {
expect(this).eql(vm)
},
itemsClick: function () {
expect(this).eql(vm)
}
}
}

const app = { doc, customComponentMap }
const vm = new Vm('foo', customComponentMap.foo, { _app: app })

checkReady(vm, function () {
doc.close()
const containerEl = vm.$el('container')
const itemsEl = vm.$el('items')
containerEl.event.click()
itemsEl.event.click()
done()
})
})

it('emit, broadcast and dispatch vm events', (done) => {
customComponentMap.foo = {
template: {
Expand Down

0 comments on commit bfed029

Please sign in to comment.