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

Computed property doesn't work in dom-repeat #1691

Closed
phanect opened this issue May 31, 2015 · 1 comment
Closed

Computed property doesn't work in dom-repeat #1691

phanect opened this issue May 31, 2015 · 1 comment

Comments

@phanect
Copy link

phanect commented May 31, 2015

When I specify computed value in dom-repeat, it doesn't work.
In the console, following warning is shown: Polymer::Attributes: couldn't decode Array as JSON, but actually this message is wrong.
When I add throw x; in deserialize function, correct error message is shown: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data.
This occurs because string csvFieldNames(_relations) is given to JSON.parse as an argument, although JSON string should be given.

Following is the example to reproduce this bug:

<link rel="import" href="/bower_components/polymer/polymer.html">

<dom-module id="import-table">
    <template is="dom-repeat" items="csvFieldNames(_relations)">
        <span>{{item}}</span>
    </template>
</dom-module>

<script>
    Polymer({ // jshint ignore:line
        is: "import-table",
        properties: {
            _relations: {
                type: Object,
                notify: true,
                value: {
                    "foo": "bar",
                    "boo": "far"
                }
            }
        },
        csvFieldNames: function(_relations) {
            return Object.keys(_relations);
        }
    });
</script>
@phanect phanect changed the title Computed property not supported in dom-repeat Computed property doesn't work in dom-repeat May 31, 2015
@arthurevans
Copy link

You're missing the mustaches around you computed binding, should be:

"{{csvFieldNames(_relations)}}"

Without the mustaches, Polymer is trying to interpret this as a JSON array literal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants