聚合物 select 值未设置

polymer select values not set

我已经设置了一个 JSbin 来显示我遇到的问题,聚合物 select 盒子没有反映模型(最初),但是,模型确实在 selecting 之后得到更新一个选项。请注意,在我的示例中,我确保在填充 select 选项后加载模型,但是,我想这里的棘手之处在于 select 框填充是嵌套的 dom-repeat(因此,当填充模块时,必须重新填充 'select' 的嵌套 dom-repeat - 我猜)。

这是 bin 以及如何测试它以显示困境。

http://jsbin.com/xucavi/edit?html,console,output

页面加载后,请注意在 2 个 select 框中没有生成 select 离子。单击 'Display Values from Model' 按钮。请注意,这些值表明模型具有值。 Select 'Digital' 用于每个 2 select 框。现在再次单击 'Display Values from Model' 按钮 - 请注意模型已更新。

关于如何解决这个问题有什么想法吗?谢谢

您需要计算 option 元素的 selected 属性的值。

修改外部 dom-repeat 以将实际书籍绑定到 属性 book 而不是 item。现在,将 selected 属性绑定到 _computeSelected(item, book) 函数可以动态计算所选图书类型:

<option value='{{item.id}}' selected$='[[_computeSelected(item, book)]]'>{{item.type}}</option>

函数本身的实现很简单:

_computeSelected: function(item, book) {
    return item.id === book.typeId;
}

您的 JS Bin 的工作示例: http://jsbin.com/sodugigubo/edit?html,console,output

如需更深入的解释,请阅读 computed binding and attribute binding

警告:请注意