Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map 渲染时三元表达式无效? #862

Closed
JoMartinezZhu opened this issue Oct 17, 2018 · 9 comments · May be fixed by lucyxss/taro#52 or pftom/taro#74
Closed

map 渲染时三元表达式无效? #862

JoMartinezZhu opened this issue Oct 17, 2018 · 9 comments · May be fixed by lucyxss/taro#52 or pftom/taro#74
Assignees

Comments

@JoMartinezZhu
Copy link

JoMartinezZhu commented Oct 17, 2018


问题描述
map 渲染时三元表达式无效

this.state.monthData.map((month, monthIndex) => {
                  return (
                    <View className='single-month' key={monthIndex + 1}>
                      <View className='month-title'>{`${this.state.year}${monthIndex + 1}月`}</View>
                      <View className='date at-row at-row--wrap'>
                        {
                          month.map((day, index) => {
                            let dayJSX = addDaysFromPreMonth[monthIndex] <= index ?
                              (<View className='day'>{day}</View>) : '';
                            return (
                              <View className='at-col at-col-1_7_1 day-wrap' key={index}>
                                {dayJSX}
                              </View>
                            );
                          })
                        }
                      </View>
                    </View>);
                })

image
### 效果图:
image
但是这样写就OK了,就是吧 上面的 jsx 表达式换成 一个字符串 ‘123’
image
### 效果图:
image
期望行为
[这里请用简洁清晰的语言描述你期望的行为]

@yuche
Copy link
Contributor

yuche commented Oct 17, 2018

我觉得问题应该在 addDaysFromPreMonth[monthIndex] <= index 这个表达式一直为 false,当我把他写为 -1 <= index 时是可以渲染的,编译也没错。

提问的时候一定记得带上你的版本号,不然像上次一样。

image

@yuche yuche self-assigned this Oct 17, 2018
@JoMartinezZhu
Copy link
Author

我觉得问题应该在 addDaysFromPreMonth[monthIndex] <= index 这个表达式一直为 false,当我把他写为 -1 <= index 时是可以渲染的,编译也没错。

提问的时候一定记得带上你的版本号,不然像上次一样。

image

Taro 版本号:1.0.7;
我这样修改之后是 可以 渲染出来的 ,这个问题 症结 是在 为什么将三元表达式的中的 JSX 表达式 改为 String 类型的 ‘123’,就可以正常渲染了呢?
image

@yuche
Copy link
Contributor

yuche commented Oct 17, 2018

「这样修改」是怎么修改?把你前面表达式修改为真吗?

当你改为 123之后也要前面的 addDaysFromPreMonth[monthIndex] <= index 这个表达式为真时才渲染。
两者不同的地方在于一个是条件渲染 dom 元素,一个是渲染 text node,关键的问题还是你前面的表达式。

@JoMartinezZhu
Copy link
Author

「这样修改」是怎么修改?把你前面表达式修改为真吗?

当你改为 123之后也要前面的 addDaysFromPreMonth[monthIndex] <= index 这个表达式为真时才渲染。
两者不同的地方在于一个是条件渲染 dom 元素,一个是渲染 text node,关键的问题还是你前面的表达式。

不对;对比一下,下面的截图,第二张是我目前的临时解决方案,两个的差别就是 三元表达式中 条件渲染 dom 元素 不同!
image
image

@JoMartinezZhu
Copy link
Author

「这样修改」是怎么修改?把你前面表达式修改为真吗?

当你改为 123之后也要前面的 addDaysFromPreMonth[monthIndex] <= index 这个表达式为真时才渲染。
两者不同的地方在于一个是条件渲染 dom 元素,一个是渲染 text node,关键的问题还是你前面的表达式。

针对 Taro 中的三元表达式以及 逻辑运算,我发现了一个 问题!

data.state === 2 ---> true
recognizeStatis --->null
时,
却得到了 这样的结果 data.state === 2 && !!recognizeStatis ----> true
我非常不解,结果 应该是 false 的
为了 解决这个问题 ,我是这样处理的
data.state === 2 && (!!recognizeStatis).toString() === 'true' ----- > false

{
              (data.state === 2 && !!recognizeStatis) && (
                <View className='practise-statistic'>
                  practise-statistic 2----{data.state}
                  {JSON.stringify(recognizeStatis)}
                  {(!recognizeStatis).toString()}
                  {averageJSX}
                  {topErrorsJSX}
                  {analysisJSX}
                </View>
              )
            }

image

@yuche
Copy link
Contributor

yuche commented Oct 18, 2018

recognizeStatis --->null

能否做一个带数据源的简单的复现?我这边似乎不会出现这个情况

@JoMartinezZhu
Copy link
Author

recognizeStatis --->null

能否做一个带数据源的简单的复现?我这边似乎不会出现这个情况

我这边做了一个简单的数据源,但是 没有出现 这个情况!能给一个简单的推断嘛,怎么会出现 这个问题呢?

@yuche
Copy link
Contributor

yuche commented Oct 18, 2018

我也不能复现所以才问你要一个能复现的版本啊

@taro-bot
Copy link

taro-bot bot commented Nov 7, 2018

Hello~

您的问题我们无法复现。如果有空的话还请拔冗提供一个简单的复现 demo,否则这个 issue 将在 15 天后被自动关闭。

如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。

Good luck and happy coding~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants