如何获取数组值并使用Mongoose进行结构化?

时间:2017-03-31 06:56:20

标签: angularjs node.js mongoose mongojs

我正在使用 MeanStack AngularJS 。我将值存储到MongoDB中,如下所示:

数据格式

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
    Enter number<br />
    <input type="number" id="user_input" name="number" /><br />
    <input type="number" id="user_input2" name="number" /><br />
    <input type="submit" id="submit" value="submit" disabled="disabled" />
</form>
<div id="test">
</div>

位指示

"RoleName" : "Verify",    
"IsActive" : true,
"UIList" : 
    {
        "UiName": "One",
        "View" : false,
        "Edit" : false
    },
    {
       "UiName": "Two",
        "View" : false,
        "Edit" : false
    },
    {
        "UiName": "Three",
        "View" : false,
        "Edit" : false
    },
    {
        "UiName": "Four",
        "View" : false,
        "Edit" : false
    },
    {
        "UiName": "Five",
        "View" : false,
        "Edit" : false
    }

服务器

$http.get('/Manage_Datashow').success(function (response) {
    $scope.Manage_Roleser = response;
});

这里我附上了我的示例代码。我想使用app.get('/Manage_Datashow', function (req, res) { db.New_Role.find(function (err, docs) { console.log(docs); res.json(docs); }); }); 绑定列表中的值。

我的代码:

ng-repeat

示例:

enter image description here

我需要这样的输出。

2 个答案:

答案 0 :(得分:2)

首先,你所有的json都不是有效的,请检查并通过以下最常见的

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.Manage_Roleser =[ {
    "RoleName" : "Verify",    
    "IsActive" : true,
    "UIList" : [{
            "UiName": "One",
            "View" : false,
            "Edit" : false
        },
        {
           "UiName": "Two",
            "View" : false,
            "Edit" : false
        },
          {
            "UiName": "Three",
            "View" : false,
            "Edit" : false
        },
         {
            "UiName": "Four",
            "View" : false,
            "Edit" : false
        },
          {
            "UiName": "Five",
            "View" : false,
            "Edit" : false
        }]
       } ]
});
<!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.12/angular.js" data-semver="1.4.9"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
 
 <div>
  
     <div  ng-repeat="i in Manage_Roleser[0].UIList">
       {{i.UiName}} | {{i.View}}   {{i.Edit}}
      
       
     </div>
   
 </div>
  </body>

</html>
 按照您的意愿添加标题。

答案 1 :(得分:1)

试试这个

&#13;
&#13;
<html>
<body>
	<div Class="container" ng-app="myapp" ng-controller="namesctrl">
		
		<table>
			<thead>
				<th>
					UiName
				</th>
				<th>
					View
				</th>
				<th>
					Edit
				</th>
			</thead>
			<tr ng-repeat="mgr in Manage_Roleser.UIList">
				<td>
					{{mgr.UiName}}
				</td>
				<td>
				|{{mgr.View}}
				</td>
				<td>
					{{mgr.View}}
				</td>
			</tr>
		</table>
	</div>  


	<script Src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.js"></script>

	<script>
		var app=angular.module("myapp", []);
		app.controller("namesctrl", function($scope){

			$scope.Manage_Roleser= 
			{
				"RoleName" : "Verify",    
    			"IsActive" : true,
				"UIList": [{
				"UiName": "One",
				"View" : false,
				"Edit" : false
			},{
				"UiName": "Two",
				"View" : false,
				"Edit" : false
			},
			{
				"UiName": "Three",
				"View" : false,
				"Edit" : false
			},
			{
				"UiName": "Four",
				"View" : false,
				"Edit" : false
			},
			{
				"UiName": "Five",
				"View" : false,
				"Edit" : false
			}]
		}
			

		});



	</script>
</body>
</html>
&#13;
&#13;
&#13;