regularjs / regular

regularjs: a living template engine that helps us to create data-driven component.
http://regularjs.github.io/
MIT License
1.06k stars 149 forks source link

调用$update方法报错 #27

Closed xw332 closed 9 years ago

xw332 commented 9 years ago
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
</head>
<body>
  <div id="wrap-comment">
    <script id="t-comment" type="text/regular">
    {#list items as el}
    123<br>
    {/list}
    </script>
  </div>

  <script src="regular.min.js"></script>
  <script type="text/javascript">
    var data = [{}];
    vComment = Regular.extend({
      template: '#t-comment'
    });
    vmComment = new vComment({
      data: {
        items: data
      , aaa: [{}]
      }
    });
    vmComment.$inject('#wrap-comment');

    setTimeout(function() {
      //vmComment.data.items = [{}, {}];
      vmComment.$update('items');
      //vmComment.$update('aaa');
    }, 100);
  </script>
</body>
</html>

报错:Uncaught TypeError: Cannot read property 'length' of undefined

leeluolee commented 9 years ago

当数据从数组变为undefined 会出现这个bug 其实已经修复了,会和其他更新一起发布到0.3.1. 你update(item)是为了将这个数组设置为undefined?

xw332 commented 9 years ago

是为了只触发这个字段的更新,难道这个函数是只能赋值的吗?

leeluolee commented 9 years ago

,update 只是有赋值的用途, 但是你这么使用会导致它变为undefined,因为第二个参数为undefined.他没有指定某个字段更新的能力。 相当于 componnt.data.items=undefined. component.$update() 传参的话其实只是一种简写方

leeluolee commented 9 years ago

fixed at https://github.com/regularjs/regular/blob/master/test/spec/browser-list.js#L386