具有ng-repeat错误的数组

时间:2015-06-24 13:11:07

标签: javascript angularjs

@Override
public void onDrawFrame(final GL10 gl) {

    zvector = new float[] {0,0,1,0};
    resultvector = new float[] {0,0,1,0};
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();

    float radiansX = (float) Math.toRadians(gyro_angle[1]);
    float radiansY = (float) Math.toRadians(-gyro_angle[0]);
    float radiansZ = (float) Math.toRadians(-gyro_angle[2]);

    // Finds the Sin and Cosin for the half angle.
    float sinX =(float) Math.sin(radiansX * 0.5);
    float cosX =(float) Math.cos(radiansX * 0.5);
    float sinY =(float) Math.sin(radiansY * 0.5);
    float cosY =(float) Math.cos(radiansY * 0.5);
    float sinZ =(float) Math.sin(radiansZ * 0.5);
    float cosZ =(float) Math.cos(radiansZ * 0.5);

    // Formula to construct a new Quaternion based on direction and angle.
    quatX[0] = cosX;
    quatX[1] = 1 * sinX;
    quatX[2] = 0 * sinX;
    quatX[3] = 0 * sinX;
    quatY[0] = cosY;
    quatY[1] = 0 * sinY;
    quatY[2] = 1 * sinY;
    quatY[3] = 0 * sinY;
    quatZ[0] = cosZ;
    quatZ[1] = 0 * sinZ;
    quatZ[2] = 0 * sinZ;
    quatZ[3] = 1 * sinZ;


    quat1 = multiplyQuat(quatX, quatY);
    quat2 = multiplyQuat(quat1, quatZ);

    mMatrix = getMatrixfromQuat(quat1);
    gl.glLoadMatrixf(mMatrix, 0);
    this.mSphere.draw(gl);
}
@Override
public void onSurfaceChanged(final GL10 gl, final int width, final int height) {
    final float aspectRatio = (float) width / (float) (height == 0 ? 1 : height);

    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    GLU.gluPerspective(gl, 45.0f, aspectRatio, 0.1f, 100.0f);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
}
@Override
public void onSurfaceCreated(final GL10 gl, final EGLConfig config) {
    this.mSphere.loadGLTexture(gl, this.mContext, R.drawable.pic360);
    gl.glEnable(GL10.GL_TEXTURE_2D);
    gl.glShadeModel(GL10.GL_SMOOTH);
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
    gl.glClearDepthf(1.0f);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glDepthFunc(GL10.GL_LEQUAL);
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
}

//CONSTRUCTER
public GlRenderer(final Context context) {
    this.mContext = context;
    this.mSphere = new Sphere(5, 2);
    sensorManager = (SensorManager) this.mContext.getSystemService(this.mContext.SENSOR_SERVICE);
    sensorGyroscope = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    sensorAccelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    sensorMagneticField = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    valuesAccelerometer = new float[3];
    valuesMagneticField = new float[3];
    matrixR = new float[9];
    matrixI = new float[9];
    matrixValues = new float[3];

    sensorManager.registerListener(this, sensorGyroscope, SensorManager.SENSOR_DELAY_FASTEST);
    sensorManager.registerListener(this, sensorAccelerometer, SensorManager.SENSOR_DELAY_FASTEST);
    sensorManager.registerListener(this, sensorMagneticField, SensorManager.SENSOR_DELAY_FASTEST);
}
//HERE GOES SOME CURRENTLY IRRELEVANT STUFF ABOUT THE SENSORS AND QUATERNIONS

请任何人帮助我

$http.get('***').success(function(data, status,response)
{ 
$scope.items=data;
var getdata=JSON.stringify(data.D_Services);
console.log(getdata);
});
im getting in console
D_Services: "Wash,Tyres,Spares,Accessories";

我需要这样的答案,请任何人帮助我

enter image description here

现在我正在enter image description here

4 个答案:

答案 0 :(得分:5)

您将“数组”声明为String

改为Array

$scope.items = ['Wash', 'Tyres', 'Spares', 'Accessories'];

如果您需要将其保留为字符串,请使用.split()

<div ng-repeat="item in items.split(',')">

答案 1 :(得分:1)

将商品存储在数组中

$scope.items = ['Wash', 'Tyres', 'Spares', 'Accessories'];

然后

<div ng-repeat="item in items">

答案 2 :(得分:0)

HTML

<div ng-controller="Test1Controller" data-ng-init="loadservice()">
<div ng-repeat="item in items">
<input type="checkbox" ng-model="item.SELECTED"  ng-true-value="'Y'" ng-false-value="'N'"/> {{item}}
</div>
</div>

在控制器中

$scope.items=["Wash","Tyres","Spares","Accessories"];

小提琴,以便更好地理解 http://jsfiddle.net/sykxr2ex/

plunker如果您想使用服务 http://plnkr.co/edit/Y0Y5o2?p=preview

答案 3 :(得分:0)

因为您希望能够为每个字符串设置选定的标志,所以您需要一个对象列表。

$scope.items=[
  {title: "Wash", selected: false},
  {title: "Tyres", selected: false}, 
  {title: "Spares", selected: false },
  {title: "Accessories", selected: false}" ];

然后您可以使用以下代码。

<div ng-controller="Test1Controller" data-ng-init="loadservice()">
  <div ng-repeat="item in items">
   <input type="checkbox" ng-model="item.selected" ng-true-value="'Y'" ng-false-value="'N'"/> {{item.title}}
  </div>
</div>