我是AngularJS和JSON的新手。我被困在這個階段,我想在JSON中過濾不必要的字段。如何在控制器內格式化JSON數據
我在我的控制器使用的代碼:
var data = $scope.choices; // Is an array
var datav = (JSON.stringify(data)); // array converted into a string need to be filtered
alert(datav);
如果我alert(datav)
我得到這下面提到的JSON數據。
[{"title":"g","$$hashKey":"object:3"},{"id":"choice2","$$hashKey":"object:6","title":"ghgh"},{"id":"choice3","$$hashKey":"object:11","title":"fgh"}]
我只是想 「稱號」 我不想$$hashKey
和id
。這個怎麼做?
你嘗試過什麼到目前爲止?你有沒有試過https://docs.angularjs.org/guide/filter或https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter? –
使用'.map()'只返回你想要的 –