从MEAN堆栈应用程序的控制器中的范围变量中选择不同的值

时间:2017-05-11 14:43:57

标签: javascript angularjs node.js

$scope.items = [
{
sourceBuildingId: "B001",
sourceBuildingName: "Building 1",
destinationBuildingId: "B002"
destinationBuildingName: "Building 2" 
},
{
sourceBuildingId: "B003",
sourceBuildingName: "Building 3",
destinationBuildingId: "B002",
destinationBuildingName: "Building 2" 
},
{
sourceBuildingId: "B001",
sourceBuildingName: "Building 1",
destinationBuildingId: "B003",
destinationBuildingName: "Building 3" 
},
{
sourceBuildingId: "B002",
sourceBuildingName: "Building 2",
destinationBuildingId: "B004",
destinationBuildingName: "Building 4" 
}];

$scope.destinationBuildingIdList="";

如何从$ scope.items中单独获取不同的建筑物ID列表并存储到$ scope.destinationBuildingIdList变量中?

1 个答案:

答案 0 :(得分:1)

只需使用javascript rs = reflect.ValueOf(MyStruct) rs2 := reflect.New(rs.Type()).Elem() rs2.Set(rs) rf = rs2.Field(0) rf = reflect.NewAt(rf.Type(), unsafe.Pointer(rf.UnsafeAddr())).Elem() // Now rf can be read. Setting will succeed but only affects the temporary copy. 函数

即可
map

演示



$scope.destinationBuildingIdList= $scope.items.map(o=> o.destinationBuildingId)

angular.module("app",[])
.controller("ctrl",function($scope){

$scope.items = [
      {
      sourceBuildingId: "B001",
      sourceBuildingName: "Building 1",
      destinationBuildingId: "B002",
      destinationBuildingName: "Building 2" 
      },
      {
      sourceBuildingId: "B003",
      sourceBuildingName: "Building 3",
      destinationBuildingId: "B002",
      destinationBuildingName: "Building 2" 
      },
      {
      sourceBuildingId: "B001",
      sourceBuildingName: "Building 1",
      destinationBuildingId: "B003",
      destinationBuildingName: "Building 3" 
      },
      {
      sourceBuildingId: "B002",
      sourceBuildingName: "Building 2",
      destinationBuildingId: "B004",
      destinationBuildingName: "Building 4" 
}];

$scope.destinationBuildingIdList= $scope.items.map(o=> o.destinationBuildingId)

console.log($scope.destinationBuildingIdList)
})