收藏
回答

setData设置属性值之前获取this设置的属性已经被改变了?但是不可用?求解

onLoad: function (options) {

var that=this;

console.log(that)

console.log("that:"+""+"roomid:"+that.data.roomId+" "+"hotelid:"+that.data.hotelId)

//这里才设置为什么前面的that属性值已经被改变了,但是不可用?

that.setData({

roomId: options.roomId,

hotelId: options.hotelId

})

console.log("this:" + " "+ "roomid:" + that.data.roomId + " " + "hotelid:" + that.data.hotelId)

},


//console.log(that)

e {data: {…}, onLoad: ƒ, onReady: ƒ, …}data: {roomId: "8d112e2b-5a23-4b3a-af99-15ee6fc30dac", hotelId: "c9633c5c-d6b4-4723-a1e3-9a2770d058a4", __webviewId__: 209}onHide: ƒ ()onLoad: ƒ ()onPullDownRefresh: ƒ ()onReachBottom: ƒ ()onReady: ƒ ()onRouteEnd: ƒ ()onShareAppMessage: ƒ ()onShow: ƒ ()onUnload: ƒ ()options: {roomId: "8d112e2b-5a23-4b3a-af99-15ee6fc30dac", hotelId: "c9633c5c-d6b4-4723-a1e3-9a2770d058a4"}route: "pages/roomdetail/roomdetail"__route__: (...)__wxWebviewId__: (...)get __route__: ƒ ()set __route__: ƒ ()get __wxWebviewId__: ƒ ()set __wxWebviewId__: ƒ ()__proto__: Object


// console.log("that:"+""+"roomid:"+that.data.roomId+" "+"hotelid:"+that.data.hotelId)

roomdetail.js? [sm]:18 that:roomid: hotelid:


//console.log("this:" + " "+ "roomid:" + that.data.roomId + " " + "hotelid:" + that.data.hotelId)

roomdetail.js? [sm]:23 this: roomid:8d112e2b-5a23-4b3a-af99-15ee6fc30dac hotelid:c9633c5c-d6b4-4723-a1e3-9a2770d058a4

求解为什么第一个that里面会无缘无故有roomId和hotelId的我明明在打印后才设置的啊!基础不扎实这个是什么原因?


回答关注问题邀请回答
收藏

1 个回答

  • 银色子弹
    银色子弹
    2017-10-27

    js是预编译机制,代码会事先编译后才是真正的执行,具体原理可度娘

    2017-10-27
    有用
    回复
登录 后发表内容