嵌套 dom-repeat & object/array 组合的挑战
Challenges with nested dom-repeat & object/array combo
我在操作 object/array 组合和让更改反映在嵌套的 dom 重复中时遇到了一些问题。它有效,但感觉像是一种 hacky 方法 - 谁能告诉我是否有更好的方法?
http://jsbin.com/dijogo/edit?html,output(仅限 Chrome)
请参阅 itemTap 函数了解具体的 hackiness 区域。或者也许有更好的方法来解决这个问题?
这样做
itemTap: function(e) {
e.model.set('i.container.value', e.model.i.container.value + ' tapped');
},
而不是
itemTap: function(e) {
//This is an overly complicated way to update a "container.value" in the items object arrays no?!
e.model.set('i.container.value', e.model.i.container.value + ' tapped');
var array = this.items[e.model.cat];
array[e.model.index].container.value += ' tapped';
this.set(['items', e.model.cat], []);
this.async(function(){this.set(['items', e.model.cat], array);});
},
嗯,你也可以
this.items = {
'One': [{container:{value: '1a'}}, {container:{value: '1b'}}],
'Two': [{container:{value: '2a'}}, {container:{value: '2b'}}],
'Three':[{container:{value: '3a'}}, {container:{value: '3b'}}]
});
而不是
this.set(['items', 'One'], [{container:{value:'1a'}}, {container:{value:'1b'}}]);
this.set(['items', 'Two'], [{container:{value:'2a'}}, {container:{value:'2b'}}]);
this.set(['items', 'Three'], [{container:{value:'3a'}}, {container:{value:'3b'}}]);
同
this.categories = ['One', 'Two', 'Three'];
我在操作 object/array 组合和让更改反映在嵌套的 dom 重复中时遇到了一些问题。它有效,但感觉像是一种 hacky 方法 - 谁能告诉我是否有更好的方法?
http://jsbin.com/dijogo/edit?html,output(仅限 Chrome)
请参阅 itemTap 函数了解具体的 hackiness 区域。或者也许有更好的方法来解决这个问题?
这样做
itemTap: function(e) {
e.model.set('i.container.value', e.model.i.container.value + ' tapped');
},
而不是
itemTap: function(e) {
//This is an overly complicated way to update a "container.value" in the items object arrays no?!
e.model.set('i.container.value', e.model.i.container.value + ' tapped');
var array = this.items[e.model.cat];
array[e.model.index].container.value += ' tapped';
this.set(['items', e.model.cat], []);
this.async(function(){this.set(['items', e.model.cat], array);});
},
嗯,你也可以
this.items = {
'One': [{container:{value: '1a'}}, {container:{value: '1b'}}],
'Two': [{container:{value: '2a'}}, {container:{value: '2b'}}],
'Three':[{container:{value: '3a'}}, {container:{value: '3b'}}]
});
而不是
this.set(['items', 'One'], [{container:{value:'1a'}}, {container:{value:'1b'}}]);
this.set(['items', 'Two'], [{container:{value:'2a'}}, {container:{value:'2b'}}]);
this.set(['items', 'Three'], [{container:{value:'3a'}}, {container:{value:'3b'}}]);
同
this.categories = ['One', 'Two', 'Three'];