从烧瓶中检索聚合物列表

Polymer retrieving list from Flask

本文关键字:聚合物 列表 检索      更新时间:2023-09-26

我需要将一个列表从Flask传递到Polymer对象。实现这一目标的最佳方式是什么?在Polymer文档中找不到列表属性类型。

<script>
    Polymer({
        is: 'create-account',
        properties: {
            actionUrl: String,
            // organizations: I want a list here of names 
        }
    });
    function submitForm() {
        document.getElementById('form').submit();
    }
</script>

accountcreation.html

<body>
    <h1>Account Creation</h1>
    <create-account action-url={{ formControllerUrl }}
                        organizations={{ organizations }}></create-account>
</body>

烧瓶功能

@home_bp.route('/create_account')
def create_account():
    import pdb
    organizations = Organization.query.with_entities(Organization.name).all()
    lst = []
    for o in organizations:
        lst.append(o[0])
    pdb.set_trace()
    return render_template('accountcreation.html', 
            formControllerUrl=url_for('form.create_account'), organzations=lst)

问题是Json中使用的引号。我应该将organizations作为'{"hello", "world"}'传递。相反,它被传递为"{"hello", "world"}"。因此,我简单地将accountcreation.html修改为:

<body>
    <h1>Account Creation</h1>
    <create-account action-url={{ formControllerUrl }}
                        organizations='{{ organizations|tojson }}'></create-account>
</body>

注意,{{ organizations|tojson }}周围的单引号。