Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't transfer attribute "onclick" to child component #1

Closed
luics opened this issue Apr 12, 2016 · 2 comments
Closed

can't transfer attribute "onclick" to child component #1

luics opened this issue Apr 12, 2016 · 2 comments
Assignees

Comments

@luics
Copy link
Member

luics commented Apr 12, 2016

<element name="foo">
  <template>
    <container style="margin-top: 40px;margin-bottom: 40px;">
      <text onclick={{onclick}}>Bind onclick, failed</text>
    </container>
  </template>
</element>

<element name="bar">
  <template>
    <container>
      <text onclick={{click}}>Bind other prop, succeed</text>
    </container>
  </template>
</element>

<template>
  <container>
    <foo onclick={{clicked}}></foo>
    <bar click={{clicked}}></bar>
    <!--<text onclick="{{clicked}}">bind onclick prop</text>-->
  </container>
</template>

<script>
  module.exports = {
    methods: {
      clicked: function() {
        this.$call('modal', 'toast', {'message': 'clicked!'});
      }
    }
  }
</script>
@luics luics changed the title muhahaha can't transfer attribute "onclick" to child component Apr 12, 2016
@luics luics assigned luics and terrykingcha and unassigned luics Apr 12, 2016
@luics luics added the bug label Apr 15, 2016
terrykingcha added a commit that referenced this issue Apr 18, 2016
Jinjiang pushed a commit that referenced this issue Apr 20, 2016
@luics
Copy link
Member Author

luics commented Apr 24, 2016

In jsfm branch, I tried demo again and find it can transfer attribute "onclick" to child component.
But in html5 preview, when I click the first line, it trigger an exception, see the below snapshot:

image

@luics luics reopened this Apr 24, 2016
@terrykingcha
Copy link
Contributor

It's a mistake for binding event. onxxx is not a attribute, you can bind a event handler on a custom component, but can't transfer the event handler into the custom component. Maybe the right code is:

<element name="foo">
  <template>
    <container style="margin-top: 40px;margin-bottom: 40px;">
      <text>foo</text>
    </container>
  </template>
</element>

<element name="bar">
  <template>
    <container>
      <text onclick={{clicked}}>Bind bar click</text>
    </container>
  </template>

  <script>
    module.exports = {
      methods: {
        clicked: function() {
          this.$dispatch('barclicked');
        }
      }
    }
  </script>

</element>

<template>
  <container>
    <foo onclick={{clicked}}></foo>
    <bar></bar>
  </container>
</template>

<script>
  module.exports = {
    ready: function() {
      var self = this;
      this.$on('barclicked', function() {
        self.$call('modal', 'toast', {'message': 'bar clicked!'});
      })
    },
    methods: {
      clicked: function() {
        this.$call('modal', 'toast', {'message': 'foo clicked!'});
      }
    }
  }
</script>

@luics luics closed this as completed Apr 27, 2016
lvscar pushed a commit that referenced this issue Jul 8, 2016
merge from alibaba/weex
sospartan added a commit that referenced this issue Jul 18, 2016
* * [android] add textarea

* * [android] fix font typeface and measure height if set line-height

* * [android] make lineheight must greater than 0
MrRaindrop pushed a commit that referenced this issue Aug 1, 2016
* [jsfm] 在 scroll.js 中取消使用 arguments.callee
Jinjiang pushed a commit that referenced this issue Sep 11, 2016
merge update from origin repo
Hanks10100 pushed a commit that referenced this issue Oct 10, 2016
merge from alibaba/weex
Hanks10100 pushed a commit that referenced this issue Oct 10, 2016
* * [android] add textarea

* * [android] fix font typeface and measure height if set line-height

* * [android] make lineheight must greater than 0
Hanks10100 added a commit that referenced this issue Oct 10, 2016
* [jsfm] 在 scroll.js 中取消使用 arguments.callee
cxfeng1-zz pushed a commit that referenced this issue Nov 2, 2016
kfeagle pushed a commit that referenced this issue Nov 28, 2016
Ios feature 20161208 :merge from origin for picker development.
lybeen pushed a commit that referenced this issue Mar 22, 2017
lybeen pushed a commit that referenced this issue Apr 17, 2017
add the component type, when the node is virtual node
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants