博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
react 二次确认框_React不确定
阅读量:2516 次
发布时间:2019-05-11

本文共 1658 字,大约阅读时间需要 5 分钟。

react 二次确认框

I've fallen in love with React.js and JSX over the years; state-based rendering and a logical workflow have made me see the light of this modern framework. That doesn't mean I don't sometimes get a bit frustrated that the "simple" things seem harder than they should be. Getting a reference to an element and modifying its properties used to be simple but now you have to take into account you don't usually have element references -- you need to think in a different way. I learned this when I needed to set a checkbox's inderterminate property, a property not recognized via an attribute, one that requires a handle on the element and setting a property directly.

这些年来,我爱上了React.js和JSX; 基于状态的渲染和合理的工作流程使我了解了这个现代框架。 这并不意味着我有时不会对“简单”的事情看起来比他们应该做的事情感到沮丧。 获取元素的引用并修改其属性以前很简单,但是现在您必须考虑到通常没有元素引用-您需要以不同的方式思考。 当我需要设置复选框的inderterminate属性时,我就学到了这一点,该属性无法通过属性识别,而该属性需要元素上的句柄并直接设置属性。

To add the indeterminate property to the checkbox, I needed to take advantage of the ref attribute:

要将indeterminate属性添加到复选框,我需要利用ref属性:

const { value, checked, indeterminate } = this.propsreturn render(     el && (el.indeterminate = indeterminate)}    />)

Since the ref is run on each render, the indeterminate property is updated appropriately, and thus the checkbox appears as expected.

由于ref在每个渲染器上运行,因此indeterminate属性会适当更新,因此该复选框将按预期显示。

Regardless of how amazing your framework appears, there's always a blind spot that requires a bit of a hack to accomplish what's expected. That's what a framework does, though: gives you 99% of what you need and makes the 1% difficult!

无论您的框架看起来有多神奇,总会有一个盲点,需要一点技巧才能完成预期的工作。 不过,这就是框架所做的事情:为您提供99%的所需内容,使1%的工作变得困难!

翻译自:

react 二次确认框

转载地址:http://jkvwd.baihongyu.com/

你可能感兴趣的文章
关于推送遇到的一些问题
查看>>
寒假作业3 抓老鼠啊~亏了还是赚了?
查看>>
Orcal Job创建实例
查看>>
Django
查看>>
批量Excel数据导入Oracle数据库(引用 自 wuhuacong(伍华聪)的专栏)
查看>>
处理移动障碍
查看>>
优化VR体验的7个建议
查看>>
2015年创业中遇到的技术问题:21-30
查看>>
《社交红利》读书总结--如何从微信微博QQ空间等社交网络带走海量用户、流量与收入...
查看>>
JDK工具(一)–Java编译器javac
查看>>
深入.NET框架与面向对象的回顾
查看>>
改变label中的某字体颜色
查看>>
七牛云存储之应用视频上传系统开心得
查看>>
struts2日期类型转换
查看>>
Spark2-数据探索
查看>>
Http和Socket连接区别
查看>>
Angular2,Springboot,Zuul,Shiro跨域CORS请求踩坑实录
查看>>
C语言中操作符的优先级大全
查看>>
pgpool-II - 介绍
查看>>
Alpha冲刺(10/10)——2019.5.2
查看>>