有谁知道当使用 ref 关键字将结构传递给方法时是否会发生装箱
struct Test
{
public int Value;
}
static void Main()
{
Test test = new Test();
SomeMethod(ref test);
System.Diagnostics.Debug.WriteLine(test.Value);
}
static void SomeMethod(ref Test test)
{
test.Value = 5;
}
Run Code Online (Sandbox Code Playgroud)
我想对类型使用结构,但我有几个方法需要更改它。如果它装箱,我只会将其传递并返回它,或者可能使用一个类来代替。
我有两个 WSDL 文件。我正在尝试在复杂类型元素中的另一个 WSDL 文件中使用在一种 WSDL 类型中定义的元素。
为此,我使用导入元素包含了另一个 WSDL 文件(otherfile.wsdl 位于同一文件夹中)。此外,我设置了命名空间并使用 ref 属性(加上命名空间)来引用其他 WSDL 文件中的元素。
但是,它抱怨来自 othertest 命名空间的元素无法从此 test.wsdl xml 模式引用。有人知道如何解决这个问题吗?
您将在下面找到这两个文件的代码:
测试.wsdl
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.example.com/test/"
xmlns:ot="http://www.example.com/othertest/"
targetNamespace="http://www.example.com/test/" >
<import namespace="http://www.example.com/othertest/" location="othertest.wsdl"/>
<types>
<xsd:schema targetNamespace="http://www.example.com/test/">
<xsd:element name="ResultElement2">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="ot:othertest_element" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</types>
</definitions>
Run Code Online (Sandbox Code Playgroud)
其他测试.wsdl
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.example.com/othertest/"
targetNamespace="http://www.example.com/othertest/" >
<types>
<xsd:schema targetNamespace="http://www.example.com/othertest/">
<xsd:element name="othertest_element">
<xsd:simpleType>
<xsd:restriction base="xsd:int"/>
</xsd:simpleType>
</xsd:element>
</xsd:schema>
</types>
</definitions>
Run Code Online (Sandbox Code Playgroud) 我想添加一个类别,然后如果成功,将它的引用推送到用户的集合。这就是我这样做的方式:
那是我的“dashboard.js”文件,其中包含类别架构。
var users = require('./users');
var category = mongoose.model('categories', new mongoose.Schema({
_id: String,
name: String,
ownerId: { type: String, ref: 'users' }
}));
router.post('/settings/addCategory', function(req, res, next) {
console.log(req.body);
var category_toAdd = new category();
category_toAdd._id = mongoose.Types.ObjectId();
category_toAdd.name = req.body.categoryName;
category_toAdd.ownerId = req.body.ownerId;
category.findOne({
name: req.body.categoryName,
ownerId: req.body.ownerId
}, function(error, result) {
if(error) console.log(error);
else {
if(result === null) {
category_toAdd.save(function(error) {
if(error) console.log(error);
else {
console.log("Added category: " + category_toAdd);
<<<<<<<<<<<<<<<<<<<THE CONSOLE LOG WORKS GOOD
users.categories.push(category_toAdd);
}
}); …Run Code Online (Sandbox Code Playgroud) 我有一个ImageListComponent包含<ReactSwipe>元素数组的数组。每个元素都有一个唯一的 ID,ref={rid}并且可以通过两张幻灯片进行滑动。ImageListComponent正在另一个名为 的组件中使用,该<CarFromImage>组件包括向<ImageListComponent>.
我遇到的问题是,在 内部,<ImageListComponent>我可以使用该方法以编程方式滑动元素this.refs[rid].swipe.prev(),但如果我想使用此方法并引用 中的特定元素,这是不可能的<CarFromImage>。
一些代码ImageListComponent.jsx:
this.props.images.map(function(image, i){
var rid = "ReactSwipe" + i;
return (<ReactSwipe ref={rid} key={i}>
<div>
<div>Something<div/>
</div>
<div>
<div style={styles.deleteIcon} onClick={this.props.deleteImage.bind(this, image, rid)}/>
</div>
</ReactSwipe>)
}
Run Code Online (Sandbox Code Playgroud)
一些代码CarFromImage.jsx:
render: function () {
return <ImageListComponent carImages={this.state.car.images} addImage={this.addImage} deleteImage={this.deleteImage}/>
Run Code Online (Sandbox Code Playgroud)
以及我想使用它的方法CarFromImage.jsx:
deleteImage: function(selectedImage, rid){
this.getFlux().actions.car.deleteImageFromCar(selectedImage);
this.refs[rid].swipe.prev();
}
Run Code Online (Sandbox Code Playgroud)
有人ref以前使用过其外部组件并知道我如何解决这个问题或者有其他建议吗?如果没有别的办法,我可以将所有内容都放入一个大的 .jsx 文件中,但我希望能够将我的项目拆分为更小的组件。任何帮助将非常感激!
我有下面的组件可以正常工作,但是如果我只是代替this.refs.searchString.value它会工作吗?event.target.value如果是这样,哪一种是首选方法?各自的优点和缺点是什么?
const SearchBar = React.createClass({
handleSubmit (event) {
event.preventDefault()
const formattedSearchString = this.refs.searchString.value.replace(/[^a-z]/gi, "").toLowerCase()
this.refs.searchString.value = ''
this.props.submitSearch(formattedSearchString)
},
render() {
return (
<form className="form form-group has-info col-md-4 text-align-center" onSubmit={this.handleSubmit}>
<input className="search-input form-control" type="text" ref="searchString" placeholder=" . . . enter pokemon name" />
<button className="btn btn-info btn-raised" type="submit" name="button">Search!</button>
</form>
)
}
})
Run Code Online (Sandbox Code Playgroud) 我正在处理大型嵌套词典,并试图删除嵌套的子词典。我想知道为什么会发生以下行为。
当我设置对字典 d 的引用(称为 ref),然后更改 ref 并打印 d 时,它会显示添加了第三个元素的 d 的更新版本。
input:
d={"a":1,"b":2}
ref=d
ref["c"]=3
print(d)
output:
{'a': 1, 'b': 2, 'c': 3}
Run Code Online (Sandbox Code Playgroud)
鉴于这种行为,我希望能够通过 delete 删除字典
input:
d={"a":1,"b":2}
ref=d
del ref
print(d)
output:
{'a': 1, 'b': 2}
Run Code Online (Sandbox Code Playgroud)
我想知道删除引用时是否有删除原始对象的方法(意味着第二个程序的输出将是错误的,因为d被删除了。
我正在尝试向特定于列表中项目的跨度标记呈现消息。我读过很多关于 React 'refs' 的内容,但不知道如何在引用消息后用消息填充跨度。
因此,有一个项目列表,每个项目行都有自己的按钮,该按钮会触发具有与该项目关联的 id 的 API。根据 API 响应,我想用响应消息更新 span 标签,但仅限于该项目
创建列表时,项目将循环通过,每个项目都包含此
<span ref={'msg' + data.id}></span><Button onClick={() => this.handleResend(data.id)}>Resend Email</Button>
Run Code Online (Sandbox Code Playgroud)
API 调用后,我想引用特定的跨度并在其中呈现正确的消息。但我无法弄清楚如何在代码的这一点上渲染到跨度。我知道这行不通,但这本质上就是我想要做的。有任何想法吗?
if (response.status === 200) {
this.refs['msg' + id] = "Email sent";
Run Code Online (Sandbox Code Playgroud) 在启用了彻底依赖规则的 React Typescript 中,当我定义一个 ref 并在效果内部使用它时,linter 就可以了:
const stringRef: RefObject<string> = useRef("Hello World!");
useEffect(() => {
console.log(stringRef.current);
}, []) // no warning, the linter detects that I'm using a ref
Run Code Online (Sandbox Code Playgroud)
但是,当我将效果放在自定义钩子中时,linter 抱怨我应该在依赖项数组中包含 ref:
const stringRef: RefObject<string> = useRef("Hello World!");
useCustomHook(stringRef);
// in another-file.ts
const useCustomHook = (ref: RefObject<string>) => {
useEffect(() => {
console.log(ref.current);
}, []) // ESLint: React Hook useEffect has a missing dependency: 'ref'. Either include it or remove the dependency array.(react-hooks/exhaustive-deps)
}
Run Code Online (Sandbox Code Playgroud)
从语义上讲,没有任何变化,但是,linter 无法识别 ref 是 RefObject(即使我是这样输入的)。 …
我想从父级获取 vue.js 组件的尺寸(我正在使用实验性脚本设置)。
当我在组件内使用 ref 时,它按预期工作。我得到尺寸:
// Child.vue
<template>
<div ref="wrapper">
// content ...
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
const wrapper = ref(null)
onMounted(() => {
const rect = wrapper.value.getBoundingClientRect()
console.log(rect) // works fine!
})
</script>
Run Code Online (Sandbox Code Playgroud)
但我想获取父组件内的维度。这可能吗?
我试过这个:
// Parent.vue
<template>
<Child ref="wrapper" />
</template>
<script setup>
import Child from './Child'
import { ref, onMounted } from 'vue'
const wrapper = ref(null)
onMounted(() => {
const rect = wrapper.value.getBoundingClientRect()
console.log(rect) // failed! …Run Code Online (Sandbox Code Playgroud) 在浏览器中获取错误 Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()
我的代码:
import { yupResolver } from '@hookform/resolvers/yup'
import { useState } from 'react'
import { SubmitHandler, useForm } from 'react-hook-form'
import { contactSchema } from 'schemas/schemas'
import { InputFloatLabel } from './components/Inputs/InputFloatLabel'
type TypeFormInput = {
name: string
email: string
textarea: string
}
export const Register = () => {
const [isLoading, setIsLoading] = useState(false)
const {
register,
handleSubmit,
formState: …Run Code Online (Sandbox Code Playgroud)