2016-03-31 12 views
0

Ich muss eine Liste von Flask zu Polymer-Objekt übergeben. Was ist der beste Weg, dies zu erreichen? Ich kann einen List-Eigenschaftstyp in der Polymer-Dokumentation nicht finden.Polymer-Abrufliste von Flask

<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> 

Flask Funktion

@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) 

Antwort

0

Das Problem mit Zitaten in Json verwendet wurde. Ich sollte organizations als solche '{"hello", "world"}' übergeben. Stattdessen wurde dies als "{"hello", "world"}" übergeben. Deshalb habe ich geändert einfach accountcreation.html als solche:

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

Hinweis, die einfachen Anführungszeichen umgeben {{ organizations|tojson }}.