在我尝试更新到聚合物1.0我得到了以下问题的数据绑定:聚合物1.0 DOM的重复绑定数组
我高分子0.5的webapp使用重复,模板来生成复选框某些类别。所有checked
值都以类别ID作为关键字绑定到数组(sortedCatsArray
)。下面是更新部分聚合物1.0我第一次尝试,但它不工作...
<template is="dom-repeat" items="{{sortedCatsArray}}" as="category">
<paper-checkbox for category$="{{category.id}}" checked="{{filterChkboxes[category.id]}}"></paper-checkbox>
</template>
正如你可以在docs阅读,这是不可能再结合同方阵列的性能 - 方括号(现在的方式:object.property
)。任何人都可以告诉我是否仍然可以将所有生成的复选框值绑定到一个数组中?
更新#1
正如你可以在docs读,阵列的具有约束力的指标,不支持。所以我试图从文档中为我的案例使用该示例,并编写了以下代码。如果我运行此代码,它似乎按预期工作:检查第一个和第三个复选框。但我也希望如果手动检查/取消选中复选框,数组将被更改。这不会发生,只有当我改变数组(在ready
- 函数)的复选框选中得到...
<dom-module id="my-index">
<link rel="import" type="css" href="/css/index.css">
<template>
<template is="dom-repeat" items="{{sortedCatsArray}}" as="category">
<paper-checkbox for category$="{{category.id}}" checked="{{arrayItem(filterChkboxes.*,category.id)}}" on-change="test"></paper-checkbox>
</template>
</template>
</dom-module>
<script>
Polymer({
is: "my-index",
properties: {
filterChkboxes: {
type: Array,
notify: true,
observer: "filterChkboxesChanged",
value: function(){return[true,false,true,false];}
},
sortedCatsArray: {
type: Array,
value: function(){return[{id: 0}, {id: 1},{id: 2},{id: 3}]},
notify: true
},
},
ready: function(){
this.set('filterChkboxes.1',true);
},
test: function(){
console.log(this.filterChkboxes);
},
observers: [
'filterChkboxesChanged(filterChkboxes.*)'
],
arrayItem: function(array, key){
return this.get(key, array.base);
},
filterChkboxesChanged: function(changes){
console.log(changes);
},
});
</script>
你有这样的工作示例吗?我认为,'checked'属性绑定到大括号内的属性。所以计算出来的属性应该返回一个变量,在该变量中存储'checked'状态。这不正确吗?但是这在我的尝试中不起作用... – Jokus
是的。发布一个简单但完整的版本,您正在尝试并且无法正常工作,因此更容易让某人发现问题。另外,请仔细看看[这里](https://www.polymer-project.org/1.0/docs/migration.html#attribute-bindings)和[这里](https://www.polymer-project.org /1.0/docs/devguide/data-binding.html#attribute-binding)。 –
好的,请看看更新后的问题;) – Jokus