this的异步绑定.bind(this)
来源:互联网 发布:网页 卡片式 数据列表 编辑:程序博客网 时间:2024/05/23 16:09
当遇到异步ajax请求时,想把请求返回的result结果赋值给ajax外定义的this对象时,直接写this.a = result;是不能成功的。例如:
this.a = {};ajaxService.AjaxPost( {},"getTimeAccount.do").then(function (result) {if(result.status){console.log('2',this);this.a = result;}});
这种写法,会报错,第6行a is not defind。
需要加上.bind(this)。如:
this.a = {};ajaxService.AjaxPost( {},"getTimeAccount.do").then(function (result) {if(result.status){console.log('2',this);this.a = result;}}.bind(this));这是异步的情况,其他情况也可以用.bind(this)来绑定运行环境。
阅读全文
0 0
- this的异步绑定.bind(this)
- React的bind(this)
- React事件处理函数中绑定this的bind()函数
- bind(this)绑定this指向的对象、箭头函数和闭包
- javascript使用bind()函数绑定this
- this的绑定规则
- this绑定
- PHP中this的绑定
- React Native 的绑定 this
- React-Native的绑定this
- React Native 的绑定 this
- React Native 的绑定 this
- JavaScript的this,call(),apply(),bind()
- JavaScript的this,call(),apply(),bind()
- react 的 bind this 几种方法
- this之后的call,apply,bind。
- $(this).bind("change",itemno_change);
- react系列-bind this
- 对于弱鸡的我,GitHub的重要功能
- 【神经网络 隐含层节点数的设置】如何设置神经网络隐藏层 的神经元个数
- 使用Intellij IDEA新建Web项目
- expdp +impdp 迁移总结
- 解决上传文件时服务端中文文件名乱码问题
- this的异步绑定.bind(this)
- Python变量类型的强制转换
- Ubuntu16.04下配置opencv及测试
- 在eclipse中报Global Settings file doesn't exist的解决办法
- 埃及分数问题 迭代加深搜索(IDDFS)
- 题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
- 比特币疯长背后的区块链技术,你知道多少
- Camel
- XCode9 打开StoryBoard崩溃问题解决办法