嵌套 dom-repeat 和对象/数组组合的挑战



我在操作对象/数组组合&使更改反映在嵌套的dom重复中。这是有效的,但感觉像是一种棘手的方法——有人能告诉我是否有更好的方法吗?

http://jsbin.com/dijogo/edit?html,输出(仅限Chrome)

请参阅itemTap功能以了解特定的黑客区域。或者也许有更好的方法来解决这个问题?

执行此

  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);});
  },

Fwiw,你也可以做

    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'];

最新更新