Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用angularjs将对象转换为数组以进行ng重复_Javascript_Angularjs - Fatal编程技术网

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,如果答案有效,请接受:)