AngularJs为JSON对象的watchCollection?

时间:2016-05-08 07:19:16

标签: javascript angularjs json

实际上我有一个JSON,它有一组对象集合。我将JSON值绑定到控件(输入)。

我试图在第一次触发的输入字段中给出值。 如果我将更改或编辑现有值,则不会触发。但是模型中的值会发生变化。

JSON:我将collections对象绑定到$ watchCollection

{
  "entityinfo": {
    "entity": "Customer29Jan16",
    "tenantid": "292FEC76-5F1C-486F-85A5-09D88096F098",
    "timestamp": "2015-12-15T10:16:06.322Z"
  },
  "collections": {
    "customer29jan16": {
      "rowset": [
        {
          "cuid": "6293f82f-d202-45c0-9a7b-46cd955361a3",
          "name": "test",
          "quantity": "60",
          "rate": "60",
          "amount": "3600"
        }
      ],
      "meta": {
        "parentreference": "***",
        "pkname": "***",
        "fkname": "***"
      },
      "rowfilter": []
    }
  }
}

控制器代码:

bosAppModule.controller("module-menu-controller", function($scope, $compile, $http) {   
    $scope.transactionalData={};
    $scope.transactionalData.Data={"entityinfo":{"entity":"Customer29Jan16","tenantid":"292FEC76-5F1C-486F-85A5-09D88096F098","timestamp":"2015-12-15T10:16:06.322Z"},"collections":{"customer29jan16":{"rowset":[{"cuid":"6293f82f-d202-45c0-9a7b-46cd955361a3","name":"test","quantity":"60","rate":"60","amount":"3600"}],"meta":{"parentreference":"***","pkname":"***","fkname":"***"},"rowfilter":[]},"customer29jan16obj":{"rowset":[{"cuobjid":"83bfc652-9f83-47d3-b173-b1a824ff3bed","fulladdress":"Electronic City","objaddr":"Bangalore","objname":"Testing","customer29jan16objcuid":"6293f82f-d202-45c0-9a7b-46cd955361a3"}],"meta":{"parentreference":"***","pkname":"***","fkname":"***"},"rowfilter":[]}}}


$scope.$watchCollection('transactionalData.Data.collections', function( newValue, oldValue ) {                        
                            console.log(newValue, oldValue);
                           // return;                       
            });
});

0 个答案:

没有答案