Comments (4)
我 console.log 发现 用类似上面的 代码去跑并没有 重新render 请问这是怎么 回事呢?
这是正确还是非正确的情况?
另外在react之外擅自修改dom,在更新父节点操作时内核会出错,可能是你没有触发此类操作吧。
from gaea-editor.
- 谢谢你的回复,我想实现 图形编辑器,看了简书的思路首先想实现视图区的拖拽,我用
<li>value</li>
的父子列 想去 模拟 所要的 随意拖拽+跨父级拖拽,这是我的测试代码。
import React from "react";
import ReactDOM from 'react-dom';
import Sortable from 'sortablejs';
class SortableExampleEsnext extends React.Component {
sortableContainersDecorator = (componentBackingInstance) => {
// check if backing instance not null
if (componentBackingInstance) {
let options = {
handle: ".group-title" // Restricts sort start click/touch to the specified element
};
Sortable.create(componentBackingInstance, options);
}
};
sortableGroupDecorator = (componentBackingInstance) => {
// check if backing instance not null
if (componentBackingInstance) {
let options = {
draggable: "li",
group: {
name: "shared",
pull: true,
put: true
},
animation: 150,
};
Sortable.create(componentBackingInstance, options);
}
};
sortableDivDecorator= (componentBackingInstance) => {
// check if backing instance not null
if (componentBackingInstance) {
let options = {
draggable: ".draggable",
group: {
name: "shared2",
pull: true,
put: true
},
animation: 150,
};
Sortable.create(componentBackingInstance, options);
}
};
render() {
console.log("Test1")
return (
<div className="container" ref={this.sortableContainersDecorator}>
<div className="group">
<h2 className="group-title">Group 1</h2>
<ul ref={this.sortableDivDecorator}>
<div className="draggable" >
<li>Sports</li>
<ul ref={this.sortableGroupDecorator}>
<li >Walking</li>
<li >Basketball</li>
<li >Gym</li>
</ul>
</div>
<div className="draggable" >
<li>Computer</li>
<ul ref={this.sortableGroupDecorator}>
<li >Programming</li>
<li >Surfing</li>
<li >Devops</li>
</ul>
</div>
<div className="draggable" >
<li>Food</li>
<ul ref={this.sortableGroupDecorator}>
<li >Meat</li>
<li >Vegetables</li>
<li >Milk</li>
</ul>
</div>
</ul>
</div>
</div>
);
}
}
ReactDOM.render(<SortableExampleEsnext />,document.getElementById('root'));
可以实现了跨父级拖拽,随意拖拽 的功能,除了父级元素被拖空之后就再也拖不进去了(不知道是不是脱离了react 控制什么的)这个情况unexpected之外,其他感觉没什么异常,我刚接触react 不久,不是很懂这算不算 擅自修改dom,我也不清楚 为啥 这样拖拽为什么不会重新render(看sortable 里面提到用ref 作为react 直接操作DOM 的 安全入口,不知道是不是这个原因),想请教一下您的看法。
- 我换了一个思路 去 学,不是跟简书上的尝试着写了,所有东西都是组建的形式结合上去的,就想一个一个分开来看看源码 学习,记得只有viewport/action.ts 用到了 Sortable, 想看到那里的时候在解决那个问题,想问下 关于 不是接触react很久的写以前写python多一点,想快速做出、掌握这个图形编辑器,您有什么建议吗?
from gaea-editor.
使用 react 时要注意,只能修改非 react 控制范围的 dom,否则会引发各种 bug,尝试去找原因也是一种无意义的行为,因为前提已经错了。
快速掌握技巧就是多看源码,这里也有现成的源码宝库,克隆一下项目拿去学吧。
from gaea-editor.
好的谢谢🙏
from gaea-editor.
Related Issues (20)
- 克隆项目 npm run start 报错 HOT 2
- Uncaught ReferenceError: Save is not defined HOT 2
- preComponents有什么作用呢? HOT 3
- src/components/box-editor/src/box-editor/box-editor.component.tsx报错 HOT 1
- npm run docs 后浏览器提示https不安全 HOT 1
- Local development run,got a mistake HOT 1
- 给组件设置margin后,hover框偏移
- [教程-图文] 关于在Window里面使用WSL(Liunx子系统)来开发gaea-editor HOT 2
- [BUG] 当属性过多的时候,无法点击到对应的添加事件的按钮 HOT 1
- window安装了包之后,启动 HOT 3
- npm run docs运行不起来 HOT 2
- 引入Editor报错,Xe.create is not a function HOT 5
- 如何初始化编辑器布局? HOT 2
- 代码没法运行 , 但是不知道什么报错 HOT 3
- 请问 container 组件的 Grow参数是什么用的 ? HOT 1
- 钉钉二维码过期 HOT 1
- npm run start 报错
- 有没有用 JavaScript 或 vue 写的类似可视化搭建库
- 源码代码找半天
- 请问如何获取editor component onchange event?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gaea-editor.