Search code examples
javascriptweex

weex.js - how to pass the loop variable into event handler


I'm running this code:

<template>
    <div>
        <text onclick="log(items[0])">outside the loop</text>
        <div repeat="item in items">
            <text onclick="log(item)">{{item}}</text>
        </div>
    </div>
</template>
<script>
    module.exports = {
        data: {
            items: ['foo']
        },
        methods: {
            log: function(item) {
                console.log(item);
            }
        }
    }
</script>

When I click the "outside the lop", I see foo, but when I click the "foo", I see undefined. How could I pass the loop variable into the event handler?


Solution

  • This demo is ok in native code environment(I test it using iOS WeexSDK). Maybe it is a bug in browser.

    By the way, you can use vuejs grammar in latest WeexSDK and it's no problem with loop variable.

    demo: http://dotwe.org/vue/658afd881a720ab0c877a5bb2d88b9f4