(Xv) Father and Son by value and Back

A Father and Son by value

1.1 from father to son

Father to son is a question mark after the url

# father.wxml
<view bindtap="clickData">{{sondata}}</view>
Father.js # 
Page ({ 
  Data: { 
    sondata: " available topics " , 
  }, 
  clickData: function () { 
    wx.navigateTo ({ URL:
       '/ Pages / Son / Son P = 123?' ,     ☆☆☆ ☆
 }) }, })

Son page is onLoad function in

# son.js
  onLoad: function (options) {
    console.log(options)
  },

1.2 Sub parent data transmission

# father.wxml
<view bindtap="clickData">{{sondata}}</view>
Father.js # 
Page ({ 
  Data: { 
    sondata: " available topics " , 
  }, 
  clickData: function () { 
    wx.navigateTo ({ 
      URL: ' / Pages / Son / Son ' , 
    }) 
  }, 
})

Son of page 

The first is the simple logic

Son.wxml #
<View class = " Containe " >
            # data for the data in the loop # js a function of binding a block in the next # data - **-past data <View class = " Item " WX: for = " {} {} topicList " bindtap = " chooseTopic " Data-dict = " {{}} Item " > <text> # item.title {} {} </ text> <text> {} {} times item.count </ text> </ View> </ View> # son.wxss .Item { padding: 40rpx; display: flex; flex
- direction: Row; The justify -content: space- the BETWEEN; } # son.js Page ({
the Data: {
  # I write here is in fact dead should be obtained from the database topicList: [ {the above mentioned id:
1 , title: ' Pork ' , COUNT: 100 }, {ID: 2 , title: ' pot package of meat ' , COUNT: 100 }, {ID: . 3 , title: ' lamb ' , COUNT: 100 }, {ID: . 4 , title: ' moo shu ', count: 100 }, ] }, })
chooseTopic function in son.js
# The first approach 
chooseTopic: function (E) {
// current topic ---- dict click on the topic resulting var toptic = e.currentTarget.dataset.dict // before the value is passed to a page var Pages and the = getCurrentPages () ; // get all the pages var prevpage = pages and the [pages.length- 2 ] // find the results page before the current page is a previous page [we] called it the object prevPage.setData ({sondata: toptic.title} ) // Object .setData assignment // jump back to the original page wx.navigateBack ({}) },
# The second approach 
chooseTopic: function (E) {
// this topic var toptic = e.currentTarget.dataset.dict // before the value is passed to a page var Pages = getCurrentPages (); var prevpage = Pages [pages.length - 2 ] prevPage.setTopicData (toptic) // is the parent page there is a function we call the function the value passed in the past // jump back to the original page wx.navigateBack ({}) },
# With the second method uses the father.js
setTopicData:function(res){
  this.setData({ sondata: res.title})
}
# Sondata: data in the parent page

 

Two Back

Get all of the current page

Then get the previous page of the current page

var pages = getCurrentPages();             
var prevPage = pages[pages.length-2]        

 The sample code

 

Guess you like

Origin www.cnblogs.com/a438842265/p/12401603.html