在我的类定义中,我想基于另一个槽的值初始化一个槽.这是我想做的事情:
(defclass my-class ()
((slot-1 :accessor my-class-slot-1 :initarg slot-1)
(slot-2 :accessor my-class-slot-2 :initform (list slot-1))))
Run Code Online (Sandbox Code Playgroud)
但是这不会编译:
1 compiler notes:
Unknown location:
warning:
This variable is undefined:
SLOT-1
warning:
undefined variable: SLOT-1
==>
(CONS UC-2::SLOT-1 NIL)
Compilation failed.
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
假设我要定义两个类类,Sentence
并且Word
.每个单词对象都有一个字符串和一个词性(pos).每个句子包含一些单词,并有一个额外的数据槽.
该Word
班是简单的定义.
wordSlots <- list(word = "character", pos = "character")
wordProto <- list(word = "", pos = "")
setClass("Word", slots = wordSlots, prototype = wordProto)
Word <- function(word, pos) new("Word", word=word, pos=pos)
Run Code Online (Sandbox Code Playgroud)
现在我想创建一个Sentence
可以包含一些Word
s和一些数值数据的类.
如果我将Sentence
类定义为:
sentenceSlots <- list(words = "Word", stats = "numeric")
sentenceProto <- list(words = Word(), stats = 0)
setClass("Sentence", slots = sentenceSlots, prototype = sentenceProto)
Run Code Online (Sandbox Code Playgroud)
那句话只能包含一个单词.我显然可以用许多插槽来定义它,每个字一个,但是它的长度会受到限制.
但是,如果我Sentence
像这样定义类:
sentenceSlots <- list(words = "list", stats = …
Run Code Online (Sandbox Code Playgroud) 请参阅下面的代码,即使指定了插槽名称,当前所有子项都在默认插槽中呈现。
不确定 vue createElement 函数是否支持命名槽?
@Component({
props:[]
})
export class TestComponent extends Widget{
items:any[];
render(h:any){
const rootcmp = {
template:`<div>
Temp:<slot name="temp"></slot>
Default:<slot></slot>
</div>`
, data:()=>{
return {};
}
}
const cmp = {
template:'<div slot="default">This is child</div>'
, data:()=>{
return {};
}
}
const cmp2 = {
template:'<div slot="temp">This is child</div>'
, data:()=>{
return {};
}
}
return h(rootcmp, [h(cmp), h(cmp2)]);
}
}
Run Code Online (Sandbox Code Playgroud)
当前行为:
<div>
Temp:Default:
<div>This is child</div>
<div>This is child</div>
</div>
Run Code Online (Sandbox Code Playgroud)
预期行为:
<div>
Temp:
<div>This is child</div> …
Run Code Online (Sandbox Code Playgroud) 我有一个像这样定义的 Web 组件自定义元素。
<template id="dropdown-template">
<select>
<slot></slot>
</select>
</template>
<script>
class Dropdown extends HTMLElement {
constructor() {
super();
const shadowRoot = this.attachShadow({mode: 'open'});
let template = document.getElementById('dropdown-template');
shadowRoot.appendChild(template.content.cloneNode(true));
}
}
customElements.define("drop-down", Dropdown);
</script>
Run Code Online (Sandbox Code Playgroud)
在尝试使用它时,我尝试将带有值的选项标签传递到自定义元素中。
<drop-down>
<option>one</option>
<option>two</option>
<option>three</option>
</drop-down>
Run Code Online (Sandbox Code Playgroud)
这不起作用。select 元素显示为具有一个<slot>
元素作为其直接子元素,并且它不呈现选项。这不可能与<select>
标签有关吗?
假设我定义了一个'foo'
带有两个插槽'a'
和的 S4 类'b'
,并定义了一个x
类的对象'foo'
,
setClass(Class = 'foo', slots = c(
a = 'numeric',
b = 'character'
))
x <- new('foo', a = rnorm(1e3L), b = rep('A', times = 1e3L))
format(object.size(x), units = 'auto') # "16.5 Kb"
Run Code Online (Sandbox Code Playgroud)
然后我想'a'
从定义中删除插槽'foo'
setClass(Class = 'foo', slots = c(
b = 'character'
))
slotNames(x) # slot 'a' automatically removed!! wow!!!
Run Code Online (Sandbox Code Playgroud)
我看到 R 会自动处理我的对象x
并'a'
移除插槽。好的!但是等等,对象的大小x
并没有减少。
format(object.size(x), units = 'auto') # …
Run Code Online (Sandbox Code Playgroud) 我需要将名称为test1 的ref 集中起来,设置一些值,该值放置在组件槽中(从外部)。有可能以某种方式做到这一点吗?我尝试从 $refs 或 $slots 获取,但失败了。
<template>
<div id="app">
<HelloWorld>
<input type="text" ref="test1" />
</HelloWorld>
</div>
</template>
```
<script>
import HelloWorld from './components/HelloWorld.vue';
export default {
name: 'App',
components: {
HelloWorld,
},
};
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
Run Code Online (Sandbox Code Playgroud)
<template>
<slot></slot>
<hr />
<input type="text" ref="test2" />
</template>
<script>
export default {
name: 'HelloWorld',
mounted() {
this.$refs.test2.value = 'test 2 …
Run Code Online (Sandbox Code Playgroud) 我是 Qt 新手,我试图理解以下信号槽连接:
m_networkManager = new QNetworkAccessManager(this);
QNetworkReply *reply = m_networkManager->get(request);
connect(reply, SIGNAL(finished()),this, SLOT(onRequestCompleted()));
Run Code Online (Sandbox Code Playgroud)
为什么我们在 get-request 之后连接“finished”信号?...如果第 2 行中的网络连接在插槽连接(第 3 行)之前执行得更快,会发生什么?
我知道,这段代码会起作用。但我想了解这是怎么可能的:)
我在创建带有信号和插槽的 QPushButton 时遇到问题。首先,我创建了一个类,其中插槽:
class A : public QWidget{
public slots:
void handleButton();
};
Run Code Online (Sandbox Code Playgroud)
有我的 handleButton 功能:在 .cpp 中
void A::handleButton(int row, int col){
m_button->setText("Example");
// resize button
m_button->resize(100,100);
}
Run Code Online (Sandbox Code Playgroud)
然后我想连接按钮。
QObject::connect(m_button, SIGNAL(clicked()),qApp, SLOT(handleButton()));
Run Code Online (Sandbox Code Playgroud)
但是当我启动应用程序时出现错误:“没有这样的插槽”有人可以帮助我吗?
在QT Creator的设计模式下,我右键单击小部件并选择“转到插槽”,它会为小部件的信号之一创建一个插槽功能。我以为这会生成一个connect()
函数来创建此连接,但是,在任何源代码中都找不到类似的东西。将小部件的信号连接到插槽功能的实际代码在哪里?谢谢
我正在尝试制作一些 VueJS 的 slot 元素的可重用模板,但效果不佳。
我面临的问题看起来像这样。我制作了 3 个 Vue 文件来构建一些模板。
Guide.vue
这将是 for 循环的单元。 ListView.vue
导入ListTemplate.vue
和Guide.vue ListTemplate
有一个v-for
用于 Rows 属性的循环ListView.vue
和一个用于 Guide.vue 的插槽。我想将v-for
循环产生的行道具传递到Guide.vue
插槽,但似乎是undefined
。因此,我尝试在包装组件元素的模板上声明插槽范围ListView.vue
,但它不起作用。
// Guide.vue
<template>
<tr onclick="location.href='info_view.html'">
<td>
<p class="alarm_h1">{{ slotProps.row.title }}</p>
<p class="alarm_h2">{{ slotProps.row.title }}</p>
<p class="alarm_h2">{{ slotProps.row.title }}</p>
</td>
</tr>
</template>
<script>
export default {
name: "guide",
props: ['slotProps', 'row']
}
</script>
// List.vue
<template>
<div>
<Guide-head/>
<List-template :rows="guides">
<template>
<component :is="tr_component"></component>
</template> …
Run Code Online (Sandbox Code Playgroud) slot ×10
qt ×3
r ×2
signals ×2
vue.js ×2
vuejs2 ×2
c++ ×1
class ×1
clos ×1
common-lisp ×1
connect ×1
javascript ×1
object ×1
qpushbutton ×1
qt-signals ×1
ref ×1
render ×1
s4 ×1
shadow-dom ×1
vuejs3 ×1