在Angular / Javascript中通过配对值分隔数组中的对象?

时间:2016-03-31 02:58:29

标签: javascript arrays angularjs json

我目前有一个包含120个对象的大型数组。每个都有一个id值和一个opposite_id值,基本上配对两个对象。循环遍历每个对象的最佳方法是,将每对放在一个新数组中还是将它们作为一对显示?

举个例子:

    Obj1 = {
        id: 1,
        opposite_id: 2,
        descr: "This is the first object"
   },
   Obj2 = {
        id: 2,
        opposite_id: 1,
        descr: "This is the second object"
   },
    Obj3 = {
        id: 3,
        opposite_id: 6,
        descr: "This is the third object"
   }

我需要最终将Obj1和Obj2一起显示(理想情况下使用ng-repeat)作为一对,同时避免显示Obj2和Obj1(因为它是重复的)...我在缠绕我的头时遇到问题如何做这个特定的行动,任何帮助将不胜感激!谢谢

1 个答案:

答案 0 :(得分:0)

这是你可以配对的一种方式。



$files = scandir('/path/to/image/directory');
foreach($files as $file){
    echo '<img src="/path/to/image/directory/' . $file . '"/><br>';
}
&#13;
private void setMarginsForChild(View child) {
    int lastItemIndex = getLayoutManager().getItemCount() - 1;
    int childIndex = getChildPosition(child);
    if(childIndex != -1) ((SampleAdapter)getAdapter()).setSelection(childIndex);
    int startMargin = childIndex == 0 ? getMeasuredWidth() / 2 : getMeasuredWidth() / 2;
    int endMargin = childIndex == lastItemIndex ? getMeasuredWidth() / 2 : getMeasuredWidth() / 2;

    //RTL works for API 17+
    if (ViewCompat.getLayoutDirection(child) == ViewCompat.LAYOUT_DIRECTION_RTL) {
        // The view has RTL layout
        ((ViewGroup.MarginLayoutParams) child.getLayoutParams()).setMargins(endMargin, 0, startMargin, 0);
    } else {
        // The view has LTR layout
        ((ViewGroup.MarginLayoutParams) child.getLayoutParams()).setMargins(startMargin, 0, endMargin, 0);
    }
    child.requestLayout();
}
&#13;
&#13;
&#13;