使用Map进行渲染时,如何从渲染数据对象外部使用变量

时间:2020-03-21 07:36:06

标签: javascript reactjs jsx

我想用JSX渲染一些数据,其中包括一些不在我用于渲染的数据中的变量。我不确定实现所需结果的最佳方法。

我尝试过的内容

地图功能下方的数据对象正在使用此对象“ tableData”的子集。在渲染中,我还尝试插入一个名为“ tableStyleCol1”的变量


  {
    id: 6,
    sectionName: 'Table: My Info',
    article: (
      <Fragment>
   <h1>This is a funky table2</h1>
      </Fragment>
    ),
    tableStyleCol1:'1',
    tableStyleCol2:'3',
    tableData:
      [
        {c1:'Hospital Number',c2:'exaMPLE - WRITE HERE'},
        {c1:' Existing Medical conditions',c2:''}
      ],
      tableType:'TableTwoColum'
  },

我用于渲染的代码在这里

  render() {
    const sectionNumber = this.props.sectionNumber;
    const currentData = this.props.data[sectionNumber]
    const elementsRender = currentData.tableData.map(elements => {
      return (
        <div className='container-flex-row border-lightgray'>
          <div className={'table-side-header gray container-flex-grow-'+this.currentData.tableStyleCol1}>
          {elements.c1}
          </div>
          <div></div>
        </div>
      );
    });
    return <h1>{elementsRender}</h1>;
  }

1 个答案:

答案 0 :(得分:1)

请勿使用 --------- beginning of crash E/AndroidRuntime: FATAL EXCEPTION: main Process: com.javapapers.androidchartapp, PID: 22809 java.lang.RuntimeException: Uncaught exception in Firebase Database runloop (3.0.0). Please report to firebase-database-client@google.com at com.google.firebase.database.android.AndroidPlatform$1$1.run(com.google.firebase:firebase-database@@16.0.4:98) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6776) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/FirebaseApp$IdTokenListener; at com.google.firebase.database.android.AndroidPlatform.newAuthTokenProvider(com.google.firebase:firebase-database@@16.0.4:112) at com.google.firebase.database.core.Context.ensureAuthTokenProvider(com.google.firebase:firebase-database@@16.0.4:246) at com.google.firebase.database.core.Context.initServices(com.google.firebase:firebase-database@@16.0.4:98) at com.google.firebase.database.core.Context.freeze(com.google.firebase:firebase-database@@16.0.4:77) at com.google.firebase.database.core.RepoManager.createLocalRepo(com.google.firebase:firebase-database@@16.0.4:92) at com.google.firebase.database.core.RepoManager.createRepo(com.google.firebase:firebase-database@@16.0.4:42) at com.google.firebase.database.FirebaseDatabase.ensureRepo(com.google.firebase:firebase-database@@16.0.4:357) at com.google.firebase.database.FirebaseDatabase.getReference(com.google.firebase:firebase-database@@16.0.4:201) at com.javapapers.androidchartapp.MainActivity.onCreate(MainActivity.java:42) at android.app.Activity.performCreate(Activity.java:6955) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045) at android.app.ActivityThread.-wrap14(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154)  at android.app.ActivityThread.main(ActivityThread.java:6776)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)  Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.FirebaseApp$IdTokenListener" on path: DexPathList[[zip file "/data/app/com.javapapers.androidchartapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.javapapers.androidchartapp-1/lib/arm64, /system/lib64, /vendor/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:380) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at com.google.firebase.database.android.AndroidPlatform.newAuthTokenProvider(com.google.firebase:firebase-database@@16.0.4:112)  at com.google.firebase.database.core.Context.ensureAuthTokenProvider(com.google.firebase:firebase-database@@16.0.4:246)  at com.google.firebase.database.core.Context.initServices(com.google.firebase:firebase-database@@16.0.4:98)  at com.google.firebase.database.core.Context.freeze(com.google.firebase:firebase-database@@16.0.4:77)  at com.google.firebase.database.core.RepoManager.createLocalRepo(com.google.firebase:firebase-database@@16.0.4:92)  at com.google.firebase.database.core.RepoManager.createRepo(com.google.firebase:firebase-database@@16.0.4:42)  at com.google.firebase.database.FirebaseDatabase.ensureRepo(com.google.firebase:firebase-database@@16.0.4:357)  at com.google.firebase.database.FirebaseDatabase.getReference(com.google.firebase:firebase-database@@16.0.4:201)  at com.javapapers.androidchartapp.MainActivity.onCreate(MainActivity.java:42)  at android.app.Activity.performCreate(Activity.java:6955)  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)  at android.app.ActivityThread.-wrap14(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:154)  at android.app.ActivityThread.main(ActivityThread.java:6776)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 。 只需使用this.currentData.tableStyleCol1