Merge pull request #28377 from Jimexist/weixin-app-getRelationNodes-fix

weixin-app: update component relationship api calls
This commit is contained in:
Armando Aguirre
2018-08-27 13:05:26 -07:00
committed by GitHub
2 changed files with 9 additions and 6 deletions
+6 -6
View File
@@ -3358,17 +3358,17 @@ type ThisTypedComponentOptionsWithRecordProps<
> &
ThisType<CombinedInstance<V, Data, Methods, Options, Readonly<Props>>>;
interface ComponentRelation {
interface ComponentRelation<T = any> {
/** 目标组件的相对关系,可选的值为 parent 、 child 、 ancestor 、 descendant */
type: string;
type: "parent" | "child" | "ancestor" | "descendant";
/** 如果这一项被设置,则它表示关联的目标节点所应具有的behavior,所有拥有这一behavior的组件节点都会被关联 */
target?: string;
/** 关系生命周期函数,当关系被建立在页面节点树中时触发,触发时机在组件attached生命周期之后 */
linked?: (...args: any[]) => void;
linked?: (target: Component<T>) => void;
/** 关系生命周期函数,当关系在页面节点树中发生改变时触发,触发时机在组件moved生命周期之后 */
linkChanged?: (...args: any[]) => void;
linkChanged?: (target: Component<T>) => void;
/** 关系生命周期函数,当关系脱离页面节点树时触发,触发时机在组件detached生命周期之后 */
unlinked?: (...args: any[]) => void;
unlinked?: (target: Component<T>) => void;
}
/**
* Component组件参数
@@ -3511,7 +3511,7 @@ interface Component<T> {
/**
* 获取所有这个关系对应的所有关联节点,参见 [组件间关系](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/custom-component/relations.html)
*/
getRelationNodes(relationKey: string): { [key: string]: ComponentRelation };
getRelationNodes(relationKey: string): ComponentRelation[];
}
declare function Component<D, M, O, P>(
options?: ThisTypedComponentOptionsWithRecordProps<Component<D>, D, M, O, P>
+3
View File
@@ -73,12 +73,15 @@ Component({
type: "parent", // 关联的目标节点应为父节点
linked(target) {
// 每次被插入到custom-ul时执行,target是custom-ul节点实例对象,触发在attached生命周期之后
target.data;
},
linkChanged(target) {
// 每次被移动后执行,target是custom-ul节点实例对象,触发在moved生命周期之后
target.data;
},
unlinked(target) {
// 每次被移除时执行,target是custom-ul节点实例对象,触发在detached生命周期之后
target.data;
}
}
}