简体   繁体   中英

PolymerJS: Pass array of items to function - Uncaught Typeerror: Converting circular structure into JSON

I've got a simple app that looks like this:

Polymer Todo应用程序

The app has a Complete All Button which should do what the label says it should and it works. But after I push the button I get the following error message in my console:

未捕获的Typeerror:将圆形结构转换为JSON

Uncaught Typeerror: Converting circular structure into JSON

This is what the function that completes all tasks looks like:

setItemsCompleted: function(completed) {
    for (var i = 0; i < this.items.length; ++i) {
        this.set(['items', i, 'completed'], completed);
    }
}

It seems to be accepting an array of items. I'd like to pass it an array of items, but this is my function that gets triggered by the complete All button:

completeAll: function(e) {
    console.log(this.items);
    this.model.setItemsCompleted(this.items);
},

Here is the code of my complete All button in my td-todos.html:

<template is="dom-if" if="{{!allCompleted}}">
    <paper-button 
        raised 
        tabindex="1" 
        class="colorful" 
        id="complete-all" 
        on-tap="completeAll">
        Complete All
    </paper-button>
</template>

My question is, how do I pass it an array of items instead of an object with the items?

Or maybe it accepting function is wrong, because it initially accepted an event fired by a checkbox that looked like this:

toggleAllCompletedAction: function(e) {
    this.model.setItemsCompleted(e.target.checked);
},

The code above is taken straight out of the TodoMVC example of the Polymer Library and just slightly modified. So the question can be reduced to, how do I use the button, instead of a checkbox?

setItemsCompleted takes a Boolean as an argument. In the original, the checked status of the checkbox is passed in. So either all items were marked as completed or not completed depending on the status of the checkbox. Now, if you want to set all to completed with a button, just pass in true .

completeAll: function(e) {
    this.model.setItemsCompleted(true);
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM