Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.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可排序json_Javascript_Jquery_Angularjs - Fatal编程技术网

Javascript angularjs可排序json

Javascript angularjs可排序json,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,我得到了一条Json消息,如下所示,在Json消息中,如果属性:description、title、option不为空,则有一个position属性。在位置数组中,有三个值,第一个值表示顺序 我试图用html打印json消息,根据顺序位置[0],我认为棘手的是,位置在不同的属性中 所以我不能用 ng-repeat="question in questions | orderBy:'Question.description.position[0] 按顺序打印html 还有别的办法吗 以下是jso

我得到了一条Json消息,如下所示,在Json消息中,如果属性:description、title、option不为空,则有一个position属性。在位置数组中,有三个值,第一个值表示顺序

我试图用html打印json消息,根据顺序位置[0],我认为棘手的是,位置在不同的属性中

所以我不能用

ng-repeat="question in questions | orderBy:'Question.description.position[0]
按顺序打印html

还有别的办法吗

以下是json消息:

[
   {
      "Question":{
         "description":{
            "default":""
         },
         "options":[
            {
               "value":{

               }
            }
         ],
         "title":{
            "text":{
               "default":"hello world"
            },
            "position":[
               0,
               12,
               0
            ]
         }
      },
      "Selection":"text"
   },
   {
      "Question":{
         "description":{
            "default":"description hello 2",
            "position":[
               2,
               12,
               0
            ]
         },
         "options":[
            {
               "value":{

               }
            }
         ],
         "title":{
            "text":{
               "default":"hello 2"
            },
            "position":[
               1,
               12,
               0
            ]
         }
      },
      "Selection":"paragraph"
   },
   {
      "Question":{
         "description":{
            "default":"description hello 3",
            "position":[
               4,
               12,
               0
            ]
         },
         "options":[
            {
               "value":{
                  "default":"1"
               },
               "position":[
                  5,
                  12,
                  0
               ]
            },
            {
               "value":{
                  "default":"2"
               },
               "position":[
                  6,
                  12,
                  0
               ]
            }
         ],
         "title":{
            "text":{
               "default":"hello 3"
            },
            "position":[
               3,
               12,
               0
            ]
         }
      },
      "Selection":"radio"
   },
   {
      "Question":{
         "description":{
            "default":"description hello 4",
            "position":[
               8,
               12,
               0
            ]
         },
         "options":[
            {
               "value":{
                  "default":"check11"
               },
               "position":[
                  9,
                  12,
                  0
               ]
            },
            {
               "value":{
                  "default":"check22"
               },
               "position":[
                  10,
                  12,
                  0
               ]
            }
         ],
         "title":{
            "text":{
               "default":"hello 4"
            },
            "position":[
               7,
               12,
               0
            ]
         }
      },
      "Selection":"checkbox"
   },
   {
      "Question":{
         "description":{
            "default":"description hello 5",
            "position":[
               12,
               12,
               0
            ]
         },
         "options":[
            {
               "value":{
                  "default":"list1"
               },
               "position":[
                  13,
                  12,
                  0
               ]
            },
            {
               "value":{
                  "default":"list2"
               },
               "position":[
                  14,
                  12,
                  0
               ]
            }
         ],
         "title":{
            "text":{
               "default":"hello 5"
            },
            "position":[
               11,
               12,
               0
            ]
         }
      },
      "Selection":"list"
   }
]

您可以将函数传递给模板中的orderBy筛选器:

ng-repeat="question in questions | orderBy:getPosition"
在控制器中:

$scope.getPosition = function(question) {
  // Your logic here to get the position according to which attributes are presents
  return position;
};

谢谢你能详细解释一下吗?从一开始,我需要知道哪个是0,然后我可以用html打印它,而不是先确定html然后再查找属性。