gpt4 book ai didi

javascript - 拖动项目时如何在Extjs中创建占位符

转载 作者:数据小太阳 更新时间:2023-10-29 03:57:08 25 4
gpt4 key购买 nike

当您将项目从一个面板拖到另一个面板时,我想在 Extjs 中创建一个占位符。项目是 dataView 记录。

Ext.application({
name: 'Fiddle',

launch: function () {
simpsonsStore = Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['id', 'name', 'email'],
data: [{
name: 'Lisa',
email: 'lisa@simpsons.com',
id: 1
}, {
name: 'Bart',
email: 'bart@simpsons.com',
id: 2
}, {
name: 'Homer',
email: 'homer@simpsons.com',
id: 3
}, {
name: 'Marge',
email: 'marge@simpsons.com',
id: 4
}]
});

Ext.create('Ext.panel.Panel', {
scrollable: 'horizontal',
bodyCls: 'scrollBarOn',
region: 'center',
width: '100%',
height: 800,
layout: 'hbox',
renderTo: Ext.getBody(),
items: [{
xtype: 'panel',
width: 200,
height: 500,
items: [{
xtype: 'dataview',
itemSelector: 'div.detail',
tpl: ['<tpl for=".">',
'<div class="detail">{name}</div>', '</tpl>'
],
margin: '0 0 0 0',
store: simpsonsStore,
scrollable: 'vertical',
focusable: false,
setTemplate: function (template, itemSelector) {
this.tpl = template;
this.itemSelector = itemSelector;
this.refresh();
},
listeners: {
render: function (v) {
var currentRef = this;
new Ext.view.DragZone({ //Create Drag Zone
view: currentRef,
ddGroup: 'kanbanDataviewDrag',
dragText: '1 row selected'
});
new Ext.view.DropZone({ //Create Drop Zone
view: currentRef,
ddGroup: 'kanbanDataviewDrag',
handleNodeDrop: function (data, record,
position) { //When Handle Node Drop
var view = this.view,
store = view.getStore(),
index, records, i, len;
if (data.copy) {
records = data.records;
data.records = [];
for (i = 0, len = records.length; i <
len; i++) {
data.records.push(records[i].copy(
records[i].getId()));
}
} else {
data.view.store.remove(data.records,
data.view === view);
}
index = store.indexOf(record);
if (position !== 'before') {
index++;
}
store.insert(index, data.records);
store.commitChanges();
}
});
}
}
}]
}, {
xtype: 'panel',
width: 200,
height: 500,
items: [{
xtype: 'dataview',
itemSelector: 'div.detail',
tpl: ['<tpl for=".">',
'<div class="detail">{name}</div>', '</tpl>'
],
margin: '0 0 0 0',
store: simpsonsStore,
scrollable: 'vertical',
focusable: false,
setTemplate: function (template, itemSelector) {
this.tpl = template;
this.itemSelector = itemSelector;
this.refresh();
},
listeners: {
render: function (v) {
var currentRef = this;
new Ext.view.DragZone({ //Create Drag Zone
view: currentRef,
ddGroup: 'kanbanDataviewDrag',
dragText: '1 row selected'
});
new Ext.view.DropZone({ //Create Drop Zone
view: currentRef,
ddGroup: 'kanbanDataviewDrag',
handleNodeDrop: function (data, record,
position) { //When Handle Node Drop
var view = this.view,
store = view.getStore(),
index, records, i, len;
if (data.copy) {
records = data.records;
data.records = [];
for (i = 0, len = records.length; i <
len; i++) {
data.records.push(records[i].copy(
records[i].getId()));
}
} else {
data.view.store.remove(data.records,
data.view === view);
}
index = store.indexOf(record);
if (position !== 'before') {
index++;
}
store.insert(index, data.records);
store.commitChanges();
}
});
}
}
}]
}]
});
}
});

fiddle :https://fiddle.sencha.com/#fiddle/1i2u

当你拖动任何项目时,我想创建这样的占位符:http://www.bryntum.com/examples/taskboard-latest/examples/kitchensink/index.html#examples/basic

最佳答案

我已经更新了您的 fiddle 示例并制定了一个可行的解决方案。主要问题是拖动时选择文本。有了这个解决方案,我们通过使用平面按钮摆脱了这个问题。

Changes

  • 已添加 index.css。
  • jetsonsStore 定义。
  • 创建 renderFunc 以删除重复代码。
  • tpl 改变了。

我没有fiddle账号,所以我会在这里分享代码。

index.css

.detail
{
border: 0;
background: none;
box-shadow:none;
border-radius: 0px;
}

app.js

var renderFunc = function(v) {
var currentRef = this;
new Ext.view.DragZone({ //Create Drag Zone
view: currentRef,
ddGroup: 'kanbanDataviewDrag',
dragText: '1 row selected'
});
new Ext.view.DropZone({ //Create Drop Zone
view: currentRef,
ddGroup: 'kanbanDataviewDrag',
handleNodeDrop: function(data, record, position) { //When Handle Node Drop
var view = this.view,
store = view.getStore(),
index, records, i, len;
if (data.copy) {
records = data.records;
data.records = [];
for (i = 0, len = records.length; i < len; i++) {
data.records.push(records[i].copy(records[i].getId()));
}
} else {
data.view.store.remove(data.records, data.view === view);
}
index = store.indexOf(record);
if (position !== 'before') {
index++;
}
store.insert(index, data.records);
store.commitChanges();
}
});
}

var itemTeplate = function(){
return '<div><button class="detail">{name}</button></div>';
}

Ext.application({
name: 'Fiddle',

launch: function() {
simpsonsStore = Ext.create('Ext.data.Store', {
fields: ['id', 'name', 'email'],
data: [
{name: 'Lisa', email: 'lisa@simpsons.com', id: 101},
{name: 'Bart', email: 'bart@simpsons.com', id: 102},
{name: 'Homer', email: 'homer@simpsons.com', id: 103},
{name: 'Marge', email: 'marge@simpsons.com', id: 104}
]
});
jetsonsStore = Ext.create('Ext.data.Store', {
fields: ['id', 'name', 'email'],
data: [
{name: 'George', email: 'george@jetsons.com', id: 201},
{name: 'Jane', email: 'jane@jetsons.com', id: 202},
{name: 'Judy', email: 'judy@jetsons.com', id: 203},
{name: 'Elroy', email: 'elroy@jetsons.com', id: 204}
]
});

Ext.create('Ext.panel.Panel', {
scrollable: 'horizontal',
bodyCls: 'scrollBarOn',
region: 'center',
width: '100%',
height: 800,
layout: 'hbox',
renderTo: Ext.getBody(),
items: [{
xtype: 'panel',
width: 200,
height: 500,
items: [
{
xtype: 'dataview',
itemSelector: 'div',
tpl: ['<tpl for=".">', itemTeplate(), '</tpl>'],
margin: '0 0 0 0',
store: simpsonsStore,
scrollable: 'vertical',
focusable: false,
mode: 'single',
setTemplate: function(template, itemSelector) {
this.tpl = template;
this.itemSelector = itemSelector;
this.refresh();
},
listeners: {
render: renderFunc
}
}
]
},
{
xtype: 'panel',
width: 200,
height: 500,
items: [
{
xtype: 'dataview',
itemSelector: 'div',
tpl: ['<tpl for=".">', itemTeplate(), '</tpl>'],
margin: '0 0 0 0',
store: jetsonsStore,
scrollable: 'vertical',
mode: 'single',
focusable: false,
setTemplate: function(template, itemSelector) {
this.tpl = template;
this.itemSelector = itemSelector;
this.refresh();
},
listeners: {
render: renderFunc
}
}
]
}]
});
}
});

关于javascript - 拖动项目时如何在Extjs中创建占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39911961/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com