我想知道是否有某种魔法可以用来解决IllegalStateException并允许JTextField"尝试在通知中变异",或者换句话说,如果触发了侦听器则设置自己的文本.
为了您的信息,我正在尝试编写一个自动完成函数,该函数返回12个枚举范围内最可能的匹配,以响应用户在JTextField中的输入.
这是代码示例.你必须原谅我笨拙的算法,这会扼杀枚举结果.我突出显示了通过注释产生异常的代码:
jtfElement1.addCaretListener(new CaretListener() {
@Override
public void caretUpdate(CaretEvent e) {
String s = jtfElement1.getText();
int[] attributes = new int[13];
// iterate through each enum
for (BaseEnumAttributes b: BaseEnumAttributes.values()) {
// iterate through the length of the current text in jtfElement1
for (int i = 0; i < s.length(); i++) {
if (s.length() <= b.toString().length()) {
if (b.toString().charAt(i) == s.charAt(i)) {
// increase the number of "hits" noted for that enum
attributes[b.ordinal()] = attributes[b.ordinal()] + 1;
}
}
} …
Run Code Online (Sandbox Code Playgroud) 我想知道是否有人知道图中路径的任何直观的交叉和变异算子?谢谢!
我正在 ES6 中使用 Jest 为 React 组件编写一些测试。在一个测试中,我需要克隆导入的 json 并变异克隆的对象,但是当我变异克隆的对象时,原始对象也会变异!
import obj from './object.json'; // obj = { name: 'someName' }
describe('Testing a component', () => {
it('Some testing', () => {
const obj2 = Object.assign({}, obj); //Clone the object
obj2.name = 'otherName'; // Muatate the object
console.log(obj); // { name: 'otherName' }
});
})
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况?为什么当我改变克隆的对象时,原始导入的对象也会改变?
我想查询createThemes到我的graphql。我的graphql查询是:
mutation{
createTheme(name: "qwe"){
theme{
id
}
}
}
Run Code Online (Sandbox Code Playgroud)
所以它出错:mutate() got multiple values for argument 'name'
您能解决并解释其打印此错误的原因。
我的代码如下:
from models import Theme as ThemeModel, Topic as TopicModel, Article as ArticleModel
...
class CreateTheme(graphene.Mutation):
class Arguments:
id = graphene.Int()
name = graphene.String()
theme = graphene.Field(lambda: Theme)
def mutate(self, name):
theme = ThemeModel(name = name)
theme.insert()
return CreateTheme(theme = theme)
...
class Mutation(graphene.ObjectType):
create_theme = CreateTheme.Field()
...
schema = graphene.Schema(query=Query, mutation = Mutation)
Run Code Online (Sandbox Code Playgroud) 我有一组对象,它们显示在我的 Vue 组件之一的 html 页面上的表格中。对象数组是处于 Vuex 存储状态的数据。
export const store = new Vuex.Store({
state: {
jobs: [{...},{...},{...},{...},{...},{...}]
},
mutations: {
sortJobs(state, sortKey) {
console.log('running mutation');
let compare = 0;
this.state.jobs.sort((a, b) => {
if (a.sortKey > b.sortKey) {
compare = 1;
} else if (b.sortKey > a.sortKey) {
compare = -1;
}
return compare;
});
}
},
getters: {
jobs: state => state.jobs
}
});
Run Code Online (Sandbox Code Playgroud)
我正在尝试对 mutation 中的对象数组进行排序sortJobs
,但它不起作用。我在我的一个组件中调用了突变。
methods: {
sortBy: function(sortKey) {
this.$store.commit('sortJobs', sortKey);
}
}
Run Code Online (Sandbox Code Playgroud)
这不会改变对象数组的顺序,也不会改变我的表中的顺序。我已经测试过我是否可以对对象数组做任何事情,当我用 …
我是graphql的新手,我遇到了这个问题,不知道如何解决。
例如我有两个表:book 和 book_author;
book 有 book_id 和 name book_author 有 book_author_id、book_id、author_name
这两个表需要在单个请求中插入值,但 book_author 表需要 book_id ,它从它自己的 book 表中生成。
有人可以帮我弄这个吗?非常感谢帮助。
预期结果是在调用 post 请求或插入时。
例如。系统生成的 book_id bk123,表 book_author 中的 book_id 也应该相同。
可能是另一个愚蠢的F#初学者的问题...但是它一直困扰着我
我似乎无法在网上找到任何答案...可能是'因为我搜索错误的条款,但是呃
无论如何我的代码如下:
let counter() =
let mutable x = 0
let increment(y :int) =
x <- x + y // this line is giving me trouble
printfn "%A" x // and this one too
increment // return the function
Run Code Online (Sandbox Code Playgroud)
Visual Studio告诉我,x
以无效的方式使用,闭包不能捕获可变变量
这是为什么?我能做些什么来让我改变它?
let a = 1
let a = 2
let b = a
Run Code Online (Sandbox Code Playgroud)
这段代码安静地编译、运行和绑定 b = 2。
但这是理想的行为吗?它确实允许编码器重用适当的值名称,没有对象被改变,但是在n行代码中间很容易在同一名称空间中意外再次使用值名称,并且实际上引入了错误通过突变。我想知道这如何符合功能范式,以及是否应该有各种警告。
我想在 faunaDB 中批量更新具有 graphQL 突变的条目列表。输入数据是来自外部来源的冠状病毒病例列表。它会经常更新。如果集合中存在条目名称,则突变应更新现有条目,如果不存在则创建新条目。
当前的 GRAPHQL 突变
mutation UpdateList($data: ListInput!) {
updateList(id: "260351229231628818", data: $data) {
title
cities {
data {
name
infected
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
图形变量
{
"data": {
"title": "COVID-19",
"cities": {
"create": [
{
"id": 22,
"name": "Warsaw",
"location": {
"create": {
"lat": 52.229832,
"lng": 21.011689
}
},
"deaths": 0,
"cured": 0,
"infected": 37,
"type": "ACTIVE",
"created_timestamp": 1583671445,
"last_modified_timestamp": 1584389018
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
架构
type cityEntry {
id: Int!
name: String!
deaths: Int! …
Run Code Online (Sandbox Code Playgroud) 我正在做一个 React JS 项目。在我的项目中,我使用 React 查询https://react-query.tanstack.com/docs/guides/mutations。我正在使用突变向服务器发出发布请求。但是当 API 调用失败并返回 onError 时,我正在尝试从服务器获取响应返回。
这是我的代码。
let [ createItem ] = useMutation(payload => createItem(payload), {
onSuccess: (response) => {
},
onError: (error) => {
// here I am trying to get the response. In axios, we can do something like error.data.server_error_code
},
onMutate: () => {
}
})
Run Code Online (Sandbox Code Playgroud)
正如您在评论中看到的那样,我试图在 onError 回调中读取从服务器返回的字段。我怎样才能做到这一点?