日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網營銷解決方案
創(chuàng)新互聯(lián)小程序教程:微信小程序組件間關系

組件間關系

定義和使用組件間關系

有時需要實現(xiàn)這樣的組件:

我們注重客戶提出的每個要求,我們充分考慮每一個細節(jié),我們積極的做好成都網站建設、成都做網站服務,我們努力開拓更好的視野,通過不懈的努力,創(chuàng)新互聯(lián)公司贏得了業(yè)內的良好聲譽,這一切,也不斷的激勵著我們更好的服務客戶。 主要業(yè)務:網站建設,網站制作,網站設計,微信小程序開發(fā),網站開發(fā),技術開發(fā)實力,DIV+CSS,PHP及ASP,ASP.Net,SQL數(shù)據(jù)庫的技術開發(fā)工程師。


   item 1 
   item 2 

這個例子中, custom-ul 和 custom-li 都是自定義組件,它們有相互間的關系,相互間的通信往往比較復雜。此時在組件定義時加入 relations 定義段,可以解決這樣的問題。示例:

// path/to/custom-ul.js
Component({
  relations: {
    './custom-li': {
      type: 'child', // 關聯(lián)的目標節(jié)點應為子節(jié)點
      linked: function(target) {
        // 每次有custom-li被插入時執(zhí)行,target是該節(jié)點實例對象,觸發(fā)在該節(jié)點attached生命周期之后
      },
      linkChanged: function(target) {
        // 每次有custom-li被移動后執(zhí)行,target是該節(jié)點實例對象,觸發(fā)在該節(jié)點moved生命周期之后
      },
      unlinked: function(target) {
        // 每次有custom-li被移除時執(zhí)行,target是該節(jié)點實例對象,觸發(fā)在該節(jié)點detached生命周期之后
      }
    }
  },
  methods: {
    _getAllLi: function(){
      // 使用getRelationNodes可以獲得nodes數(shù)組,包含所有已關聯(lián)的custom-li,且是有序的
      var nodes = this.getRelationNodes('path/to/custom-li')
    }
  },
  ready: function(){
    this._getAllLi()
  }
})
// path/to/custom-li.js
Component({
  relations: {
    './custom-ul': {
      type: 'parent', // 關聯(lián)的目標節(jié)點應為父節(jié)點
      linked: function(target) {
        // 每次被插入到custom-ul時執(zhí)行,target是custom-ul節(jié)點實例對象,觸發(fā)在attached生命周期之后
      },
      linkChanged: function(target) {
        // 每次被移動后執(zhí)行,target是custom-ul節(jié)點實例對象,觸發(fā)在moved生命周期之后
      },
      unlinked: function(target) {
        // 每次被移除時執(zhí)行,target是custom-ul節(jié)點實例對象,觸發(fā)在detached生命周期之后
      }
    }
  }
})

注意:必須在兩個組件定義中都加入relations定義,否則不會生效。

關聯(lián)一類組件

有時,需要關聯(lián)的是一類組件,如:


  
    input
    
  
   submit 

custom-form 組件想要關聯(lián) custom-input 和 custom-submit 兩個組件。此時,如果這兩個組件都有同一個behavior:

// path/to/custom-form-controls.js
module.exports = Behavior({
  // ...
})
// path/to/custom-input.js
var customFormControls = require('./custom-form-controls')
Component({
  behaviors: [customFormControls],
  relations: {
    './custom-form': {
      type: 'ancestor', // 關聯(lián)的目標節(jié)點應為祖先節(jié)點
    }
  }
})
// path/to/custom-submit.js
var customFormControls = require('./custom-form-controls')
Component({
  behaviors: [customFormControls],
  relations: {
    './custom-form': {
      type: 'ancestor', // 關聯(lián)的目標節(jié)點應為祖先節(jié)點
    }
  }
})

則在 relations 關系定義中,可使用這個behavior來代替組件路徑作為關聯(lián)的目標節(jié)點:

// path/to/custom-form.js
var customFormControls = require('./custom-form-controls')
Component({
  relations: {
    'customFormControls': {
      type: 'descendant', // 關聯(lián)的目標節(jié)點應為子孫節(jié)點
      target: customFormControls
    }
  }
})

relations 定義段

relations 定義段包含目標組件路徑及其對應選項,可包含的選項見下表。

選項 類型 是否必填 描述
type String 目標組件的相對關系,可選的值為 parent 、 child 、 ancestor 、 descendant
linked Function 關系生命周期函數(shù),當關系被建立在頁面節(jié)點樹中時觸發(fā),觸發(fā)時機在組件attached生命周期之后
linkChanged Function 關系生命周期函數(shù),當關系在頁面節(jié)點樹中發(fā)生改變時觸發(fā),觸發(fā)時機在組件moved生命周期之后
unlinked Function 關系生命周期函數(shù),當關系脫離頁面節(jié)點樹時觸發(fā),觸發(fā)時機在組件detached生命周期之后
target String 如果這一項被設置,則它表示關聯(lián)的目標節(jié)點所應具有的behavior,所有擁有這一behavior的組件節(jié)點都會被關聯(lián)


文章題目:創(chuàng)新互聯(lián)小程序教程:微信小程序組件間關系
標題鏈接:http://m.5511xx.com/article/cdodsoh.html