gpt4 book ai didi

javascript - 下划线,清除对象的所有值但保留键

转载 作者:行者123 更新时间:2023-11-28 19:24:41 26 4
gpt4 key购买 nike

我不知道这是否可能,但我试图做的是“清理”一个对象。基本想法是我有一个对象的表格(以 Angular ),然后单击我想添加一个新行(控制对象中的一个新项目,但我希望它没有值。我有下划线尝试一下。一些考虑因素是传入的对象每次都会有不同的键值,所以我试图保持这种多态性(如果可能的话)。

这就是我到目前为止所拥有的:

<!-- 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;
}
}

关于javascript - 下划线,清除对象的所有值但保留键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28097146/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com