NG-重复排序依据对象 [英] ng-repeat orderBy object

查看:143
本文介绍了NG-重复排序依据对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:

我使用如下面的我的HTML页:

on my html page I'm using as the following:

<section ng-repeat="template in templates">
        <ng-include src="template"></ng-include>
    </section>

但问题是,我需要在一定的顺序具体文件,因此是有办法,我可以控制顺序呈现的方式吗?

but the problem is that I need specific file in certain order so is there a way I can control the way order is rendering?

我想排序依据的对象我怎么做,我已经在这里张贴之前在网上搜索。

I'm trying to orderby an object how do I do that and I have searched online before posting it here.

function MyCtrl($scope) {
    $scope.templates = {
        template_address: "../template/address.html",
        template_book: "../template/book.html",
        template_create: "../template/create.html" 
    };



<div ng-app ng-controller="MyCtrl">
    <ul>
        <li ng-repeat="(name, path) in templates">{{name}}: {{path}}</li>
    </ul>
</div>

http://jsfiddle.net/abuhamzah/6fbpdm9m/

推荐答案

幸得ryeballar

Credit goes to ryeballar

http://stackoverflow.com/a/27466368/275390

而不是使用一个键 - 值对象的,为什么不使用数组? NG-重复订单由迭代对象/数组的索引迭代。

Instead of using a key-value object, why not use an array? ng-repeat orders the iteration by the index of the iterated object/array.

叉DEMO

  $scope.templates = [
    'create.html',
    'book.html',
    'address.html'
  ];

这篇关于NG-重复排序依据对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆