提交 8213c4aa 编写于 作者: D dongzhanwu

update doc of ts-universal-events-drag-drop

Signed-off-by: Ndongzhanwu <dongzhanwu1@huawei.com>
上级 86c07bb1
......@@ -81,6 +81,8 @@
### 示例1
```ts
import UDMF from '@ohos.data.UDMF';
@Observed
class ClassA {
public name: string
......@@ -105,11 +107,27 @@ class ClassA {
struct DragExample {
@State arr: ClassA[] = [new ClassA('A', true), new ClassA('B', true), new ClassA('C', true)]
@State dragIndex: number = 0
@State mTextNew: string = ''
@State mBool: boolean = false
changeIndex(index1: number, index2: number) { // 交换数组位置
[this.arr[index1], this.arr[index2]] = [this.arr[index2], this.arr[index1]];
}
public getDataFromUDMFWithRetry(event: DragEvent) {
let records = event.getData().getRecords();
if (records) {
let plainText = <UDMF.PlainText> (records[0])
this.mTextNew = plainText.textContent
this.mBool = false
return;
}
// 获取失败延时 1.5s 再次获取
setTimeout(() => {
this.getDataFromUDMFWithRetry(event)
}, 1500)
}
build() {
Column() {
Row({ space: 15 }) {
......@@ -130,8 +148,7 @@ struct DragExample {
}
.listDirection(Axis.Horizontal)
.onDrop((event: DragEvent, extraParams: string) => { // 绑定此事件的组件可作为拖拽释放目标,当在本组件范围内停止拖拽行为时,触发回调。
let jsonString = JSON.parse(extraParams);
this.changeIndex(this.dragIndex, jsonString.insertIndex)
this.getDataFromUDMFWithRetry(event);
})
}.padding({ top: 10, bottom: 10 }).margin(10)
......@@ -187,6 +204,8 @@ struct Child {
```ts
// xxx.ets
import UDMF from '@ohos.data.UDMF';
@Extend(Text) function textStyle () {
.width('25%')
.height(35)
......@@ -201,6 +220,8 @@ struct DragExample {
@State numbers: string[] = ['one', 'two', 'three', 'four', 'five', 'six']
@State text: string = ''
@State bool: boolean = true
@State mBool: boolean = false
@State mTextNew: string = ''
@State eventType: string = ''
@State appleVisible: Visibility = Visibility.Visible
@State orangeVisible: Visibility = Visibility.Visible
......@@ -222,6 +243,20 @@ struct DragExample {
}
}
public getDataFromUDMFWithRetry(event: DragEvent) {
let records = event.getData().getRecords()
if (records) {
let plainText = <UDMF.PlainText> (records[0])
this.mTextNew = plainText.textContent
this.mBool = false
return;
}
// 获取失败延时 1.5s 再次获取
setTimeout(() => {
this.getDataFromUDMFWithRetry(event)
}, 1500)
}
build() {
Column() {
Text('There are three Text elements here')
......@@ -291,6 +326,7 @@ struct DragExample {
console.log('List onDragLeave, ' + extraParams + 'X:' + event.getX() + 'Y:' + event.getY())
})
.onDrop((event: DragEvent, extraParams: string) => {
if (!extraParams.empty()) {
let jsonString = JSON.parse(extraParams);
if (this.bool) {
// 通过splice方法插入元素
......@@ -298,6 +334,8 @@ struct DragExample {
this.bool = false
}
this.fruitVisible[this.idx] = Visibility.None
}
this.getDataFromUDMFWithRetry(event);
})
}.width('100%').height('100%').padding({ top: 20 }).margin({ top: 20 })
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册