Javascript 使用angularjs将对象转换为数组以进行ng重复
我创建了两个全局变量 例如Javascript 使用angularjs将对象转换为数组以进行ng重复,javascript,angularjs,Javascript,Angularjs,我创建了两个全局变量 例如var DiscountRef={};var shareDetail=[] 当用户添加表单时,我将所有值存储在DiscountRef变量中,例如 RefValue = {Mobile:9876543210,Quantity:3} $scope.shareDetail = Object.Keys(RefValue);//I try Object.entries also 当我想在表中显示数据时 {{shareDetail}} <div ng-repeat=&quo
var DiscountRef={};var shareDetail=[]代码>
当用户添加表单时,我将所有值存储在DiscountRef变量中,例如
RefValue = {Mobile:9876543210,Quantity:3}
$scope.shareDetail = Object.Keys(RefValue);//I try Object.entries also
当我想在表中显示数据时
{{shareDetail}}
<div ng-repeat="share in shareDetail">
{{share.Mobile}}
{{share.Quantity}}
</div>
{{shareDetail}
{{share.Mobile}
{{share.Quantity}
它显示空数组
我也试过这个
<div ng-repeat="(key, value) in shareDetail">
{{key}} : {{value}}
</div>
{{key}}:{{value}
它将得到结果。我如何访问特定的键值对,例如MobileNo:9876543210和Quantity:3
$scope.value = {Mobile:9876543210,Quantity:3};
$scope.shareDetail = [];
Object.keys($scope.value).forEach(function(key, value)
{
$scope.shareDetail.push({"item_name": key, "value": $scope.value[key]});
});
然后您可以重复执行以下操作:
<div ng-repeat="(key, item) in shareDetail">
{{item.item_name}} : {{item.value}}
</div>
{{item.item_name}:{{{item.value}
谢谢试试这个:$scope.shareDetail=[RefValue];我已经在上面的代码中得到了结果,但我希望在a标记中使用Mobile,Quantity value,比如你有Mobile&Quantity value,那么你面临什么问题?@Michael我已经更新了我的代码,请你现在试试,让我知道。谢谢你能来@Michael,如果答案有效,请接受:)