使用数组AngularJS的对象打印表

时间:2017-06-13 15:35:39

标签: javascript angularjs angularjs-ng-repeat

我有一个看起来像这样的对象:

{
  item1: [element1, element2],
  item2: [element1, element2],
  item3: [element1, element2],
  item4: [element1, element2]
}

我要做的是打印一个表,每个数组的每个元素都在一个新行中。我遇到的问题是如何在不重复整个divtable ng-repeat的情况下获取内容。

示例:

<table ng-repeat="(key, value) in accounts">
  <tr ng-repeat="element in value">
    <td>{{element}}</td>
  </tr>
</table>

这为每个key.提供了一个新表我只有一个表,每个数组元素都有一行。有角度的任何方式或我需要使用javascript吗?

1 个答案:

答案 0 :(得分:1)

将元素混合到一个数组中可能会更容易,然后重复该数组:

#include "../include/CallbackFunctions.h"
#include "../include/Text.h"

extern int dim;



void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);

    //Drawing stuff

    glFlush();
    glutSwapBuffers();
}

void idle()
{
    display();
}

/* This callback function is called whenever the window is resized or reshaped */
void reshape(int width, int height)
{
    //Width To Height Ratio
    float w2h = (height>0)? (float)width/height : 1;
    glViewport(0, 0, width, height);
    projection(w2h);
}


void projection(float asp)
{
    //Setting up the Viewing Matrix
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    if(toggleProjection==0)
    {
    glOrtho(-dim*asp, +dim*asp, -dim, +dim, -dim, +dim);
    }
    else
    {
        float fov = 55.0, near = asp/5, far = asp*5;
        gluPerspective(fov, asp, near, far);
        //To do
    }
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

/* This callback function is called when there is no activity in the window */
void keyboard(unsigned char key, int x, int y)
{
    switch(key)
    {
    case 27:
        exit(0);
        break;
    }
    keyboardKey = key;
    glutPostRedisplay();
}


/* This callback function is called whenever a keyboard interrupt is encountered */
void specialKeyboard(int key, int state, int a)
{

    int currentModifier = glutGetModifiers();
    switch(currentModifier)
    {
    case GLUT_ACTIVE_SHIFT:
        modifier = "SHIFT";
        break;
    case GLUT_ACTIVE_CTRL:
        modifier = "CTRL";
        break;
    case GLUT_ACTIVE_ALT:
        modifier = "ALT";
        break;
    }
    switch(key)
    {
    case GLUT_KEY_F1:
        if(toggleProjection=0)
        {
            toggleProjection = 1;
            view = "perspective";
            break;
        }
        else
        {
            toggleProjection = 0;
            view = "orthographic";
            break;
        }
    }
    glutPostRedisplay();
}


void mouse(int button, int state, int x, int y)
{
    if(button == GLUT_LEFT_BUTTON)
        mouseButtonPressed = "Left";
    else if(button == GLUT_RIGHT_BUTTON)
        mouseButtonPressed = "Right";

    if(state == GLUT_DOWN)
        mouseState = "down";
    else if(state == GLUT_UP)
        mouseState = "up";
}

void mouseMotion(int x, int y)
{
    mouseX = x;
    mouseY = y;
}



/*void info()
{
    displayTextAt(-130, -40, 0, "mouseButton: %s", mouseButtonPressed);
    displayTextAt(-130, -50, 0, "mouseButtonState: %s", mouseState);
    displayTextAt(-130, -60, 0, "mouseX: %d", mouseX);
    displayTextAt(-130, -70, 0, "mouseY: %d", mouseY);
    displayTextAt(-130, -80, 0, "keyboard key: %c", keyboardKey);
    displayTextAt(-130, -90, 0, "modifier: %s", modifier);
    displayTextAt(70, -90, 0, view);
}*/

然后是HTML:

$scope.elements = Object.keys($scope.accounts).reduce(function(arr, key) {
    return arr.concat($scope.accounts[key])
}, []);