角度材料md-select使用track by但仍然获得$$ hashKey

时间:2016-03-05 17:22:28

标签: angularjs angular-material angularjs-track-by

我正试图摆脱angular添加到模型值的$$ hashKey值。根据大多数实施轨道的来源应该解决这个问题,但我做错了。

vm.productTypes是id属性为GUID的任何对象数组。

产生的模型值......

while (rowPoint != NULL)
{
    point  = rowPoint->firstInRow;

    while (point != NULL)
    {
        os << point->row;
        os << ' ';
        os << point->column;
        os << ' ';
        os << point->data;
        os << endl;
        point = point->right;
    }

    rowPoint = rowPoint->nextRow;
}

HTML代码:

$$hashKey: "object:445"
id: "9e695340-d10a-40ca-9cff-e9a93388912a"
name: "Medical"
type: 1
typeString: "ProductTypes"

我哪里错了?

更新

似乎name属性导致了这种奇怪的行为。错误? http://codepen.io/anon/pen/LNpMYJ

2 个答案:

答案 0 :(得分:2)

使用ng-model-options="{ trackBy: '$value.id' }"

  • 如果您通过$http调用获取列表数据,请首先准备model对象,然后加载列表数据。
  • 或者准备模型对象并放入一个保存孔形式数据的对象

    Link

答案 1 :(得分:0)

        <html>
<head>
<title>$$HaskKey Remover</title>
    <script src="https://code.angularjs.org/1.3.8/angular.min.js></script>
        <script>
        var myApp= angular.module('MyApp', []);
        myApp.controller('MainCtrl', ['$scope',
          function($scope) {
         $scope.list = [
              {key: "1", name: "Rose"},
              {key: {id:2}, name: "Sachin"},
              {key: {id:3}, name: "Sandy"}
            ];
           console.log($scope.list);
          }
        ]);
        </script>
        <head>
        <title>Removing $$hashKey when using ng-options</title>
        </head>
        <body ng-app='MyApp'>
            <div ng-controller='MainCtrl'>
        <form>   
           <label for="Select Box">Make a choice of Players:</label>
            <select name="selectBx" id="selectBx" ng-model="optionsData"
               ng-options="item.name for item in list track by item.key">
              </select>
        </form>
          </div>
        </body>

        </html>