聚合物重复工作但不打印值

时间:2015-08-30 09:30:42

标签: javascript polymer electron

过去几天我一直在Electron应用程序中玩Polymer,我有点卡住,我有一个dom-repeat似乎有效,但它不会输出任何值里面的对象。我做错了什么?

这是元素:

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

<dom-module id="account-list">

  <template>
    <ul class="accounts">
      <li class="all_inboxes mailbox account">
        All Mailboxes
      </li>
      <template is="dom-repeat" items="{{accounts}}" as="connected_account">
        <li class="account">
          <img src$="https:{{connected_account.gravatar}}">
          {{connected_account.account.user}}
          <ul class="mailboxes">
            <template is="dom-repeat" items="{{connected_account.mailboxes}}" as="mailbox">
              <li class="mailbox">
                {{mailbox.name}}
                <span class="mailbox--badge">{{mailbox.box.messages.new}}</span>
                <span class="mailbox--status">{{mailbox.ready}}</span>
              </li>
            </template>
          </ul>
        </li>
      </template>
    </ul>
  </template>

  <script>
    'use strict'

    Polymer({
      is: 'account-list',

      ready: function ready() {
        this.accounts = []

        // Get the IMAP connector.
        let ImapConnection = require('./backend/email/imap')

        // Get the inbox class.
        let Mailbox = require('./backend/email/mailbox')

        // Get the accounts to get inboxes for.
        let imap_accounts = require('./backend').database.getAccountsList()

        // Get the gravatar lib so we can get urls for each account.
        let gravatar = require('gravatar')

        // Open all the inboxes.
        imap_accounts.forEach(function(account) {
          // Create a server for this account.
          const server = new ImapConnection(account)

          // Create an account object to render from.
          let connected_account = {
            account: account.toJSON(),
            mailboxes: [],
            gravatar: gravatar.url(account.user)
          }

          // Get this connections mailboxes.
          server.getMailBoxes(function(mailboxes) {
            connected_account.mailboxes = mailboxes

            // Push the account to the array.
            this.push('accounts', connected_account)
          }.bind(this))
        }.bind(this))
      }
    })
  </script>
</dom-module>

这就是输出(减去标记):

All Mailboxes
 {{connected_account.account.user}}
{{mailbox.name}} false
{{mailbox.name}} false
{{mailbox.name}} false
{{mailbox.name}} false
{{mailbox.name}} false
{{mailbox.name}} false
{{mailbox.name}} false
{{mailbox.name}} false
 {{connected_account.account.user}}
{{mailbox.name}} false
{{mailbox.name}} false
{{mailbox.name}} false

这是数据结构:

account: Object
    host: "imap.gmail.com"
    name: "accounts"
    password: "nopassword"
    port: 993
schema: Object
tls: true
user: "fake@gmail-address.com"
__proto__: Object
gravatar: "//www.gravatar.com/avatar/123"
mailboxes: Array[8]
    0: Mailbox
        box: Object
        callQueue: Set
        connection: Connection
        name: "Deleted Messages"
        ready: true
        __proto__: Object

1 个答案:

答案 0 :(得分:2)

确保在绑定元素的文本内容时,该元素中没有其他内容。例如,在以下代码中,li项包含数据绑定AND span

          <li class="mailbox">
            {{mailbox.name}}
            <span class="mailbox--badge">{{mailbox.box.messages.new}}</span>

您可以通过将绑定包装在另一个元素(例如span)中来解决此问题。

          <li class="mailbox">
            <span>{{mailbox.name}}</span>

另一件不起作用的事情是<img src$="https:{{connected_account.gravatar}}">。绑定必须跨越整个属性。如果要连接字符串,则必须使用computed bindings