Skip to content

watch on array does not work correctly #8

@xzer

Description

@xzer

If we watch to a existing array and then add items to the existing array, the watch function will not work correctly:

  Aj.init(function ($scope) {

    $scope.data = {
      list: []
    };

    $scope.snippet("ul").bind($scope.data, {
      list:{
        _duplicator: "li",
        _item: {
          "nnn": {
            _selector: ".x-watch",
            _watch: {
              _fields: ["name"],
              _cal: function(v){
                console.log("cal", v);
                return v+"-watched";
              }
            },
            _render: function(target, nv, ov, ctx){
              console.log("args", arguments);
              console.log("idx:", ctx.getArrayAssistant().getIndex());
              target.text(nv);
            }
          }
        }
      }
    });

    $scope.data.list.push({
      name: "name-" + i
    });
}

Workaround is to reassign a new array reference to replace the existing array:

    $scope.data.list = Aj.util.clone($scope.data.list);
    $scope.data.list.push({
      name: "name-" + i
    });

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions