下划线,清除对象的所有值,但保留键
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}
相关文章:
- 分派点击事件并保留击键修饰符
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- 单击jquery清除输入值
- 如何使用jquery强制一个单词更改大小写等以保留品牌
- 提交后保留下拉选择的值
- 刷新后保留对网页的更改
- 在mvc应用程序中,在回发时保留最初隐藏的文本框的隐藏或可见状态
- Flash Uploadify在调用我的MVC控制器时没有保留会话/授权
- 如何在Microsoft VirtualEarth 6.3中使用纯javascript清除整个形状层
- 清除以前的$_GET值或不获取仅隐藏字段的值
- 当设置addFromAutocompleteOnly时,剩余文本将保留在输入字段中
- 使用递归属性迭代保留属性结构
- Jquery html() 和保留元素名称
- 如何将字符串拆分为字符,但在javascript中保留空格
- 下划线,清除对象的所有值,但保留键
- 清除 html 输入保留后退(ctrl+z)
- Javascript,在确认窗口中按OK后清除表单.但如果取消确认,则保留表单数据
- 清除表单输入并保留占位符
- 如何在javascript中清除cookie而不保留任何到期时间
- 是“;清除“;Javascript中的保留字