Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.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/3/html/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:如何洗牌/合并来自不同ng repeat的内容_Javascript_Html_Angularjs_Ng Repeat_Shuffle - Fatal编程技术网

Javascript AngularJS:如何洗牌/合并来自不同ng repeat的内容

Javascript AngularJS:如何洗牌/合并来自不同ng repeat的内容,javascript,html,angularjs,ng-repeat,shuffle,Javascript,Html,Angularjs,Ng Repeat,Shuffle,我在另一个ng重复列表中有x个ng重复,如下所示: <div ng-repeat="object in objects"> <div ng-repeat="item in object"> <a href="{{url}}"><p>{{title}}</p></a> </div> <div ng-repeat="item in object"> <a href="{

我在另一个ng重复列表中有x个ng重复,如下所示:

<div ng-repeat="object in objects">

  <div ng-repeat="item in object">
    <a href="{{url}}"><p>{{title}}</p></a>
  </div>
  <div ng-repeat="item in object">
    <a href="{{url}}"><p>{{title}}</p></a>
  </div>
  <div ng-repeat="item in object">
   <a href="{{url}}"><p>{{title}}</p></a>
  </div>

</div>
我试图在不改变JSON对象的情况下呈现所有被洗牌的
的内容。我尝试了如下一些洗牌功能(我在SO中发现):

像这样称呼它
shuffle(对象)在控制器上,但显然我只随机获得主对象内的块对象,而不是内容本身。问题是,我不知道如何“分解”对象或将内部对象合并为一个对象,以洗牌它


我还尝试在DOM中创建ng repeat数据后对其进行洗牌,但找不到合并ng repeat数据的方法。我只是在学习AngularJS,所以我不知道这是否是实现我需要的更好的方法。如何做到这一点?谢谢如果我理解你的问题,你需要这个:

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

  var fullData = {
    "responseData": 
        { "object": 
                {
                    "url":"http://agenciabai.es/category/university/feed/", 
                    "title":"BAIANAI", 
                    "link":"http://agenciabai.es", 
                    "entries":
                        [ 
                            {
                              "title":"¡Hora de Aventuras!", 
                              "link": "http://agenciabai.es/hora-de-aventuras/", 
                              "publishedDate":"Fri, 26 Feb 2016 09:50:16", 
                              "contentSnippet": "text. "
                            }, 
                            {
                                "title":"Lo mejor de Shijue", 
                              "link":"http://agenciabai.es/lo-mejor-de-shijue/", 
                              "publishedDate":"Wed, 27 Jan 2016 04:07:23 ", 
                              "contentSnippet": "text. "
                            } 
                        ] 
                 } 
        }, 
    "responseStatus": 200
};

var data = fullData.responseData.object.entries


  $scope.arrTitles = _.map(data, 'title');

  $scope.arrDesc = _.map(data, 'link');

  $scope.shuffleTitles = _.shuffle($scope.arrTitles)
  $scope.shuffleDesc = _.shuffle($scope.arrDesc)

  $scope.shuffleData = _.zip($scope.shuffleTitles, $scope.shuffleDesc);


});
我这样做是为了展示它是如何工作的:


如果我理解你的问题,你需要:

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

  var fullData = {
    "responseData": 
        { "object": 
                {
                    "url":"http://agenciabai.es/category/university/feed/", 
                    "title":"BAIANAI", 
                    "link":"http://agenciabai.es", 
                    "entries":
                        [ 
                            {
                              "title":"¡Hora de Aventuras!", 
                              "link": "http://agenciabai.es/hora-de-aventuras/", 
                              "publishedDate":"Fri, 26 Feb 2016 09:50:16", 
                              "contentSnippet": "text. "
                            }, 
                            {
                                "title":"Lo mejor de Shijue", 
                              "link":"http://agenciabai.es/lo-mejor-de-shijue/", 
                              "publishedDate":"Wed, 27 Jan 2016 04:07:23 ", 
                              "contentSnippet": "text. "
                            } 
                        ] 
                 } 
        }, 
    "responseStatus": 200
};

var data = fullData.responseData.object.entries


  $scope.arrTitles = _.map(data, 'title');

  $scope.arrDesc = _.map(data, 'link');

  $scope.shuffleTitles = _.shuffle($scope.arrTitles)
  $scope.shuffleDesc = _.shuffle($scope.arrDesc)

  $scope.shuffleData = _.zip($scope.shuffleTitles, $scope.shuffleDesc);


});
我这样做是为了展示它是如何工作的:



你能在角度舞台前洗牌吗?在创建JSON对象之前?嗯,一点也不,因为这会让我改变整个项目的方法。最好按原样维护JSON对象——我将用这个细节更新这个问题。是否有相关的代码?你能在有角度的javascript中洗牌然后显示它吗?你可以使用一个过滤器来洗牌你的数据。这可能会有帮助:或者你可以使用orderby过滤器:只需给你的对象分配一个随机数并对它们进行排序:你能在角度阶段之前洗牌吗?在创建JSON对象之前?嗯,一点也不,因为这会让我改变整个项目的方法。最好按原样维护JSON对象——我将用这个细节更新这个问题。是否有相关的代码?你能在有角度的javascript中洗牌然后显示它吗?你可以使用一个过滤器来洗牌你的数据。这可能会有帮助:或者您可以使用orderby筛选器:只需为对象指定一个随机数并对其进行排序:实际上,我的对象看起来是这样的:
var data=[{object{subObject{entries:{title:'he',desc:'for male'}},{subObject{entries:{title:'she',desc:'for female'},},{subObject{entries:{title:'I',desc:'for me'}}}
所以你的小提琴不合适。很抱歉我的解释不好,我是新手,解释问题本身是我发现最难的。我也更新了问题的对象。这不是有效的json数据,你能添加一个真正的json响应吗?想象一下“responseData”中更多的“object”项:
{“responseData”:{对象:{“url”:http://agenciabai.es/category/university/feed/“,”标题“:”贝亚奈“,”链接“:”http://agenciabai.es,“条目”:[{“标题”:“Hora de Aventuras!”,“链接”:http://agenciabai.es/hora-de-aventuras/,“publishedDate”:“Fri,2016年2月26日09:50:16”,“contentSnippet”:text.},{“title”:“Lo mejor de Shijue”“链接”:http://agenciabai.es/lo-mejor-de-shijue/,“publishedDate”:“Wed,2016年1月27日04:07:23”,“contentSnippet”:text.},]}},“responseStatus”:200})
我修复了JSFIDLE,我希望它现在可以工作,但是它仍然不能工作。我需要一个更高层次的深度。我需要的是混合每个entrie和所有条目。我更新了对象的原样:alives!实际上我的对象看起来是这样的:
var data=[{object{subObject]{条目:{title:'he',desc:'for male'}}}},{subObject{entries:{title:'she',desc:'for female'},}},{subObject{entries:{title:'I',desc:'for me'}}
所以你的小提琴不合适。很抱歉我的解释不好,我是新手,解释问题本身是我发现最难的。我也更新了问题的对象。这不是有效的json数据,你能添加一个真正的json响应吗?想象一下“responseData”中更多的“object”项:
{“responseData”:{”对象“{”url:”http://agenciabai.es/category/university/feed/“,”标题“:”贝亚奈“,”链接“:”http://agenciabai.es,“条目”:[{“标题”:“Hora de Aventuras!”,“链接”:http://agenciabai.es/hora-de-aventuras/,“publishedDate”:“Fri,2016年2月26日09:50:16”,“contentSnippet”:text.},{“title”:“Lo mejor de Shijue”“链接”:http://agenciabai.es/lo-mejor-de-shijue/,“publishedDate”:“Wed,2016年1月27日04:07:23”,“contentSnippet”:text.},]}},“responseStatus”:200})
我修复了JSFIDLE,我希望它现在可以工作,但是它仍然不起作用。我需要一个更高层次的深度。我需要的是混合每个entrie和所有条目。我更新了FIDLE对象的原样:尊敬!
  angular.module("app", []).controller("BarCtrl", function ($scope) {

  var fullData = {
    "responseData": 
        { "object": 
                {
                    "url":"http://agenciabai.es/category/university/feed/", 
                    "title":"BAIANAI", 
                    "link":"http://agenciabai.es", 
                    "entries":
                        [ 
                            {
                              "title":"¡Hora de Aventuras!", 
                              "link": "http://agenciabai.es/hora-de-aventuras/", 
                              "publishedDate":"Fri, 26 Feb 2016 09:50:16", 
                              "contentSnippet": "text. "
                            }, 
                            {
                                "title":"Lo mejor de Shijue", 
                              "link":"http://agenciabai.es/lo-mejor-de-shijue/", 
                              "publishedDate":"Wed, 27 Jan 2016 04:07:23 ", 
                              "contentSnippet": "text. "
                            } 
                        ] 
                 } 
        }, 
    "responseStatus": 200
};

var data = fullData.responseData.object.entries


  $scope.arrTitles = _.map(data, 'title');

  $scope.arrDesc = _.map(data, 'link');

  $scope.shuffleTitles = _.shuffle($scope.arrTitles)
  $scope.shuffleDesc = _.shuffle($scope.arrDesc)

  $scope.shuffleData = _.zip($scope.shuffleTitles, $scope.shuffleDesc);


});