[英]Underscore, clear all values of an object but keep keys
我不知道这是否可行,但是我试图做的是“清理”一个对象。 基本思想是,我有一个表(按角度)馈入一个对象,然后单击以添加一个新行(控制对象中有一个新项,但我不希望其中包含任何值)。需要考虑的是,每次进入的对象都将具有不同的键值,所以我试图保持这种多态性(如果可能)。
所以这就是我到目前为止:
<!-- model here for faces, could potentially not be seperate model and read off a length -->
<div class="inputRepeater" ng-repeat="face in inputFaces" ng-show="face.isCurrent" >
<div class="trialGrid" ng-init="$faceIndex = $index">
<table st-table="rowCollection" class="table table-striped">
<thead>
<tr>
<!-- table headers here - this can change if keys are not table exactly table headers with a bit of logic to change table headers to correct titles -->
<th ng-repeat="(key, val) in rowCollection[0]">{{key}}</th>
</tr>
</thead>
<tbody>
<!-- limit length by current face index + 1 -->
<tr ng-repeat="row in rowCollection | limitTo: $faceIndex + 1" ng-class=" { 'curentRowTab2' : $index == $faceIndex }">
<td ng-repeat="item in row">{{item}}</td>
</tr>
</tbody>
</table>
</div>
<div class="stateTab2Progress"><div class="tab2ShiftLeft" ng-click="faceLeft($index)" ng-show="!$first"><i class="fa fa-angle-left"></i></div><div class="progessTitle">Title</div><div class="progessCurrent">Current Progression {{$index + 1}}/{{inputFaces.length}}</div><div class="tab2ShiftRight" ng-show="!$last" ng-click="faceRight($index)"><i class="fa fa-angle-right"></i></div><div class="tab2ShiftRight" ng-show="$last" ng-click="faceRightLast($index)"><i class="fa fa-angle-right"></i></div></div>
<div class="state2Buttons">Buttons Also Built dynamically</div>
<button class="tab2Finish" ng-click="startTab3()">Finish</button>
</div>
</div>
因此,仅当您位于最后一个对象上时,才显示单击右键(最后一个)功能
$scope.faceRightLast = function(index){
//copy current row and empty so we keep a polymorphic format, then add it onto current object, thus adding new empty object
var storeRow = $scope.inputFaces[index];
//push new face on face tracking array
$scope.inputFaces.push({'isCurrent' : false });
storeRow - clear values out?
//after we have a fresh row change the is current
$scope.inputFaces[index].isCurrent = false;
$scope.inputFaces[index + 1].isCurrent = true;
}
因此,我正在复制当前级别,然后希望清除该值并保留键,然后将其推入对象。
可能是这种情况,还是我应该找出新的方法。
谢谢!
var newObject = angular.copy(oldObject);
for(var key in newObject){
if(newObject.hasOwnProperty(key)){
newObject[key] = null;
}
}
var newObject = _.object(_.keys(oldObject));
_.object(_.keys({'a':1,'b':2,'c':3}))
// Object {a: undefined, b: undefined, c: undefined}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.