reactive-cocoa-3 相关问题


如何在 cocoa 中以编程方式切换 NSTextView 中的富文本格式

我想在 NSTextView 中切换富文本格式。我尝试过以下操作: [contentView setRichText:NO]; [contentView setImportsGraphics:NO]; 但是,这并没有改变 NSTextView 内容......


Angular Reactive Form - 验证在 formGroup 中不起作用

我定义了这个表单组 获取 createItem(): FormGroup { 返回 this.formBuilder.group({ 名称:['',验证器.required], 电子邮件:['',验证器.required], 手机:[...


Spring Reactive 使用 ServerRequest 获取正文 JSONObject

我是春季反应新手。 我正在尝试使用邮递员从服务器获取请求信息。 首先,postman使用post方法向服务器发送信息。 其次,我们一直在努力...


Spring Cloud Gateway 返回 404 未找到错误

我尝试使用 Reactive 和 MVC Spring Cloud API 网关,但在两次尝试中我都在 Postman 中收到 404 Not Found 错误响应。 我只有一个用户服务和一个发现服务器(尤里卡)...


Vue 3如何获取$children的信息

这是我在 Tabs 组件中使用 VUE 2 的旧代码: 创建(){ this.tabs = this.$children; } 标签: .... 这是我在 Tabs 组件中使用 VUE 2 的旧代码: created() { this.tabs = this.$children; } 标签: <Tabs> <Tab title="tab title"> .... </Tab> <Tab title="tab title"> .... </Tab> </Tabs> VUE 3: 如何使用组合 API 获取有关 Tabs 组件中子项的一些信息?获取长度,迭代它们,并创建选项卡标题,...等?有任何想法吗? (使用组合API) 这是我现在的 Vue 3 组件。我使用 Provide 来获取子 Tab 组件中的信息。 <template> <div class="tabs"> <div class="tabs-header"> <div v-for="(tab, index) in tabs" :key="index" @click="selectTab(index)" :class="{'tab-selected': index === selectedIndex}" class="tab" > {{ tab.props.title }} </div> </div> <slot></slot> </div> </template> <script lang="ts"> import {defineComponent, reactive, provide, onMounted, onBeforeMount, toRefs, VNode} from "vue"; interface TabProps { title: string; } export default defineComponent({ name: "Tabs", setup(_, {slots}) { const state = reactive({ selectedIndex: 0, tabs: [] as VNode<TabProps>[], count: 0 }); provide("TabsProvider", state); const selectTab = (i: number) => { state.selectedIndex = i; }; onBeforeMount(() => { if (slots.default) { state.tabs = slots.default().filter((child) => child.type.name === "Tab"); } }); onMounted(() => { selectTab(0); }); return {...toRefs(state), selectTab}; } }); </script> 选项卡组件: <script lang="ts"> export default defineComponent({ name: "Tab", setup() { const index = ref(0); const isActive = ref(false); const tabs = inject("TabsProvider"); watch( () => tabs.selectedIndex, () => { isActive.value = index.value === tabs.selectedIndex; } ); onBeforeMount(() => { index.value = tabs.count; tabs.count++; isActive.value = index.value === tabs.selectedIndex; }); return {index, isActive}; } }); </script> <template> <div class="tab" v-show="isActive"> <slot></slot> </div> </template> 哦伙计们,我解决了: this.$slots.default().filter(child => child.type.name === 'Tab') 对于想要完整代码的人: 标签.vue <template> <div> <div class="tabs"> <ul> <li v-for="tab in tabs" :class="{ 'is-active': tab.isActive }"> <a :href="tab.href" @click="selectTab(tab)">{{ tab.name }}</a> </li> </ul> </div> <div class="tabs-details"> <slot></slot> </div> </div> </template> <script> export default { name: "Tabs", data() { return {tabs: [] }; }, created() { }, methods: { selectTab(selectedTab) { this.tabs.forEach(tab => { tab.isActive = (tab.name == selectedTab.name); }); } } } </script> <style scoped> </style> 标签.vue <template> <div v-show="isActive"><slot></slot></div> </template> <script> export default { name: "Tab", props: { name: { required: true }, selected: { default: false} }, data() { return { isActive: false }; }, computed: { href() { return '#' + this.name.toLowerCase().replace(/ /g, '-'); } }, mounted() { this.isActive = this.selected; }, created() { this.$parent.tabs.push(this); }, } </script> <style scoped> </style> 应用程序.js <template> <Tabs> <Tab :selected="true" :name="'a'"> aa </Tab> <Tab :name="'b'"> bb </Tab> <Tab :name="'c'"> cc </Tab> </Tabs> <template/> 我扫描子元素的解决方案(在对 vue 代码进行大量筛选之后)是这样的。 export function findChildren(parent, matcher) { const found = []; const root = parent.$.subTree; walk(root, child => { if (!matcher || matcher.test(child.$options.name)) { found.push(child); } }); return found; } function walk(vnode, cb) { if (!vnode) return; if (vnode.component) { const proxy = vnode.component.proxy; if (proxy) cb(vnode.component.proxy); walk(vnode.component.subTree, cb); } else if (vnode.shapeFlag & 16) { const vnodes = vnode.children; for (let i = 0; i < vnodes.length; i++) { walk(vnodes[i], cb); } } } 这将返回子组件。我对此的用途是我有一些通用的对话框处理代码,用于搜索子表单元素组件以咨询其有效性状态。 const found = findChildren(this, /^(OSelect|OInput|OInputitems)$/); const invalid = found.filter(input => !input.checkHtml5Validity()); 如果你复制粘贴与我相同的代码 然后只需向“选项卡”组件添加一个创建的方法,该方法将自身添加到其父级的选项卡数组中 created() { this.$parent.tabs.push(this); }, 使用脚本设置语法,您可以使用useSlots:https://vuejs.org/api/sfc-script-setup.html#useslots-useattrs <script setup> import { useSlots, ref, computed } from 'vue'; const props = defineProps({ perPage: { type: Number, required: true, }, }); const slots = useSlots(); const amountToShow = ref(props.perPage); const totalChildrenCount = computed(() => slots.default()[0].children.length); const childrenToShow = computed(() => slots.default()[0].children.slice(0, amountToShow.value)); </script> <template> <component :is="child" v-for="(child, index) in childrenToShow" :key="`show-more-${child.key}-${index}`" ></component> </template> 我对 Ingrid Oberbüchler 的组件做了一个小改进,因为它不支持热重载/动态选项卡。 在 Tab.vue 中: onBeforeMount(() => { // ... }) onBeforeUnmount(() => { tabs.count-- }) 在 Tabs.vue 中: const selectTab = // ... // ... watch( () => state.count, () => { if (slots.default) { state.tabs = slots.default().filter((child) => child.type.name === "Tab") } } ) 我也遇到了同样的问题,在做了很多研究并问自己为什么他们删除了$children之后,我发现他们创建了一个更好、更优雅的替代方案。 这是关于动态组件的。 (<component: is =" currentTabComponent "> </component>). 我在这里找到的信息: https://v3.vuejs.org/guide/component-basics.html#dynamic-components 希望这对你有用,向大家问好!! 我发现这个更新的 Vue3 教程使用 Vue 插槽构建可重用的选项卡组件对于与我相关的解释非常有帮助。 它使用 ref、provide 和ject 来替换我遇到同样问题的this.tabs = this.$children;。 我一直在遵循我最初发现的构建选项卡组件(Vue2)的教程的早期版本创建您自己的可重用 Vue 选项卡组件。 根据 Vue 文档,假设您在 Tabs 组件下有一个默认插槽,您可以直接在模板中访问该插槽的子级,如下所示: // Tabs component <template> <div v-if="$slots && $slots.default && $slots.default()[0]" class="tabs-container"> <button v-for="(tab, index) in getTabs($slots.default()[0].children)" :key="index" :class="{ active: modelValue === index }" @click="$emit('update:model-value', index)" > <span> {{ tab.props.title }} </span> </button> </div> <slot></slot> </template> <script setup> defineProps({ modelValue: Number }) defineEmits(['update:model-value']) const getTabs = tabs => { if (Array.isArray(tabs)) { return tabs.filter(tab => tab.type.name === 'Tab') } else { return [] } </script> <style> ... </style> 并且 Tab 组件可能类似于: // Tab component <template> <div v-show="active"> <slot></slot> </div> </template> <script> export default { name: 'Tab' } </script> <script setup> defineProps({ active: Boolean, title: String }) </script> 实现应类似于以下内容(考虑一组对象,每个部分一个,带有 title 和 component): ... <tabs v-model="active"> <tab v-for="(section, index) in sections" :key="index" :title="section.title" :active="index === active" > <component :is="section.component" ></component> </app-tab> </app-tabs> ... <script setup> import { ref } from 'vue' const active = ref(0) </script> 另一种方法是使用 useSlots,如 Vue 文档(上面的链接)中所述。 在 3.x 中,$children 属性已被删除并且不再受支持。相反,如果您需要访问子组件实例,他们建议使用 $refs。作为数组 https://v3-migration.vuejs.org/writing-changes/children.html#_2-x-syntax 在 3.x 版本中,$children 已被删除且不再受支持。使用 ref 访问子实例。 <script setup> import { ref, onMounted } from 'vue' import ChildComponent from './ChildComponent .vue' const child = ref(null) onMounted(() => { console.log(child.value) // log an instance of <Child /> }) </script> <template> <ChildComponent ref="child" /> </template> 详细信息:https://vuejs.org/guide/essentials/template-refs.html#template-refs 基于@Urkle的回答: /** * walks a node down * @param vnode * @param cb */ export function walk(vnode, cb) { if (!vnode) return; if (vnode.component) { const proxy = vnode.component.proxy; if (proxy) cb(vnode.component.proxy); walk(vnode.component.subTree, cb); } else if (vnode.shapeFlag & 16) { const vnodes = vnode.children; for (let i = 0; i < vnodes.length; i++) { walk(vnodes[i], cb); } } } 除了已接受的答案之外: 而不是 this.$root.$children.forEach(component => {}) 写 walk(this.$root, component => {}) 这就是我让它为我工作的方式。


jQuery Ajax 在 php 同一页面上传递值 - 更新

如何找回: 如何找回: <div id="test"> <?php if (isset($_POST['sweets'])) { ob_clean(); echo $_POST['sweets']; exit; } ?> </div> <form id="a" action="" method="post"> <select name="sweets" onchange="change()" id="select1"> <option >Chocolate</option> <option selected="selected">Candy</option> <option >Taffy</option> <option >Caramel</option> <option >Fudge</option> <option >Cookie</option> </select> </form> <!-- Script --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script> function change() { var sweets = $("#select1").val(); $.ajax({ type: "POST", data: { sweets: sweets }, success: function(data) { $("#test").html(data); } }); } </script> 将值传递给 php 字符串: $string = $_POST['sweets']; <!-- I'm looking for this: --> 我希望这是可能的。我在 stackoverflow 和 google 上寻找答案,但找不到适合我的目的的答案。 对于同一个页面的ajax/PHP脚本,可以将PHP放在脚本的最前面,当有POST提交数据时以exit结束 为了使其更有意义,您应该返回与您通过 POST 提交的内容相关的内容(这是甜食的类型),作为示例,我们展示其一般定义。我们可以使用 switch,这是用于此目的的常用结构: switch ($string) { case "Chocolate": echo "Chocolate is made from cocoa beans, the dried and fermented seeds of the cacao tree"; break; case "Candy": echo "Candy is a sweet food made from sugar or chocolate, or a piece of this"; break; case "Taffy": echo "Taffy is a type of candy invented in the United States, made by stretching and/or pulling a sticky mass of a soft candy base"; break; case "Caramel": echo "Caramel is made of sugar or syrup heated until it turns brown, used as a flavouring or colouring for food or drink"; break; case "Fudge": echo "Fudge is a dense, rich confection typically made with sugar, milk or cream, butter and chocolate or other flavorings"; break; case "Cookie": echo "A cookie (American English) or biscuit (British English) is a baked snack or dessert that is typically small, flat, and sweet"; break; } exit; } ?> 所以以下是示例代码: <?php if (isset($_POST['sweets'])) { // ob_clean(); $string = $_POST['sweets']; switch ($string) { case "Chocolate": echo "Chocolate is made from cocoa beans, the dried and fermented seeds of the cacao tree"; break; case "Candy": echo "Candy is a sweet food made from sugar or chocolate, or a piece of this"; break; case "Taffy": echo "Taffy is a type of candy invented in the United States, made by stretching and/or pulling a sticky mass of a soft candy base"; break; case "Caramel": echo "Caramel is made of sugar or syrup heated until it turns brown, used as a flavouring or colouring for food or drink"; break; case "Fudge": echo "Fudge is a dense, rich confection typically made with sugar, milk or cream, butter and chocolate or other flavorings"; break; case "Cookie": echo "A cookie (American English) or biscuit (British English) is a baked snack or dessert that is typically small, flat, and sweet"; break; } exit; } ?> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <select name="sweets" onchange="change()" id="select1"> <option value="">Please select</option> <option >Chocolate</option> <option >Candy</option> <option >Taffy</option> <option >Caramel</option> <option >Fudge</option> <option >Cookie</option> </select> <br><br> <div id="test"></div> <script> function change() { var sweets = $("#select1").val(); $.ajax({ type: "POST", data: { sweets: sweets }, success: function(data) { $("#test").html(data); } }); } </script>


pandas 系列替换为回填替代品

pandas.Series.replace 的文档包含一个示例: >> 将 pandas 导入为 pd >> s = pd.Series([1, 2, 3, 4, 5]) >> s.replace([1, 2], method='bfill') 0 3 1 3 2 3 ...


使用指向c中数组的指针返回二维数组

#包括 int (*createArray())[3] { 静态 int arr[2][3] = {{1, 2, 3}, {4, 5, 6}}; 返回 arr; } int main() { int (*ptr)[3] = createArray(); 对于 (int i = 0; i &l...


如何执行 QtWidgets.QTableWidget.setHorizontalHeader() 来保持默认行为?

pyqt5。常规表: 从 PyQt5 导入 QtWidgets 应用程序 = QtWidgets.QApplication([]) 表 = QtWidgets.QTableWidget(3, 3) table.setHorizontalHeaderLabels(['1', '2', '3']) 表.show() app.exec_()...


Python 3 str.join() 保证顺序吗?

Python 3(标准实现)是否保证以下代码始终生成字符串 2, 3, 1? ', '.join(['2', '3', '1']) 如果是,此功能(订单保持)在哪里记录?...


gridview点击后如何知道点击了哪个单元格

我有一个 PROJECT_EFFORT 表。 项目 ID、年份、月份、工作量 1, 2022, 12, 10 2, 2022, 12, 20 2, 2023, 1, 100 2, 2023, 2, 50 2, 2023, 3, 30 3, 2023, 3, 40 3, 2023, 4, 10 3, 2023, 5, 120 4、...


在js中查找数组的所有子集

这里我编写了一个程序,它将找到所有子集数组,就像数组是 [1, 2, 3] 一样,我想要输出像 [[], 2],, 2, , [2, 1 ], 3, , [3, 1], [3, 2], [3 我写了一个程序


YugabyteDB 中 3 个集群的双向异步复制

我有 3 个集群,每个集群有 3 个节点。所有 3 个集群均使用双向引导复制进行链接。我正在做一些压力测试。 场景 1:其中一个数据中心发生故障...


将 R 中 3 个变量的总和重新调整为恰好等于 1

我有一个如下数据框,其中有 3 列,每列代表在单个活动中花费的时间比例。 df <- data.frame(ID = c(1, 2, 3, 4), (time_1 = c(0.25...


如何在 DolphinDB 中使用元编程重写脚本?

st = take(`a, 7) 加入 take(`b, 6) 日期 = 2023.08.01 + 0 1 3 6 7 8 9 0 1 2 3 8 9 值 = 35 34 35.79 33.26 32.88 33.73 31 25 24 22 25.79 21 31 t = 表(st、日期、val) 市场日 = 2023.08.01 + 0 1 2 3...


Python 将字节数据的字符串表示转换为浮点数据

我通过网络套接字发送了 12 个字节,用于表示 3 个浮点值。另一个程序执行此操作: 浮点 m_floatArray[3]; ... Serial.write((byte*) m_floatArray, 12); //12 b/c 3 浮在 4


使用sympy求解具有绝对值的两侧不等式

比较简单的数学题,求3的范围<= Abs[6 - x] <= 5. Not hard to solve by hand, and Mathematica nails it, with the answer 1 <= x <= 3 || 9 <= x <= 11. The


Pinia 对象在 Vue 中的 foreach 后失去反应性

我有这个嵌套的foreach BalanceItemList.vue ... 我有这个嵌套的 foreach BalanceItemList.vue <template> <div v-for="category in categoryItemsStore.balanceCategories" :key="category.id" class="mt-5"> <div class="border-black border-b bg-gray-200"> <span class="font-bold w-full">{{ category.name }}</span> </div> <div v-for="balanceItem in category.balance_items" :key="balanceItem.id"> {{ balanceItem.total = 500 }} <balance-item :balance-item="balanceItem" @update-balance-item="update"/> </div> <div> <balance-item-create :category="category.id" @create-balance-item="update"/> </div> <div v-if="categoryItemsStore.totals[category.id]" class="grid grid-cols-4-b t-2 ml-2"> <div :class="category.is_positive ? '': 'text-red-600' " class="col-start-4 border-t-2 border-black font-bold"> &euro;{{ categoryItemsStore.totals[category.id].total }} </div> </div> </div> </template> 我像这样检查了“balanceItem”的反应性 {{ balanceItem.total = 500 }} 它在商店中更新,但随后我有了我的平衡项目组件: BalanceItem.vue <script setup> import {reactive} from "vue"; import {useForm} from "@inertiajs/vue3"; import NumberInput from "@/Components/NumberInput.vue"; import {UseCategoryItemsStore} from "@/Stores/UseCategoryItemsStore.js"; const categoryItemStore = UseCategoryItemsStore() const props = defineProps({balanceItem: Object, errors: Object}) let item = reactive(props.balanceItem); const form = useForm(item); const emit = defineEmits(['update-balance-item']) const submit = () => { form.post(route('balance-item.update'), { preserveScroll: true, onSuccess: () => { props.balanceItem.total = 500 categoryItemStore.updateBalanceItemsTotals(form) emit('update-balance-item') } }) } </script> <template> <form @submit.prevent="submit"> <div class="grid grid-cols-4-b"> <span>{{ item.name }}</span> <NumberInput v-model="form.count" autofocus class=" mr-4 mt-1 block" type="number" @update:model-value="submit" /> <div :class="item.item_category.is_positive ? '' : 'text-red-600'" class="flex place-items-center"> <div class="pt-1 mr-1">&euro;</div> <NumberInput v-model="form.amount" :class="form.errors.amount ? 'border-red-600' : ''" autofocus class="mt-1 mr-4 w-5/6" type="text" @update:model-value="submit" /> </div> <div :class="item.item_category.is_positive ? '' : 'text-red-600'" class="flex place-items-center"> <div class="pt-1 mr-1 w-5/6">&euro;</div> <NumberInput v-model="form.total" autofocus class="mt-1 block" disabled style="max-width: 95%" type="text" /> </div> </div> </form> </template> 这是我测试反应性的商店。如果我增加输入的数字,则项目的计数保持不变 UseCategoryItemsStore.js import {defineStore} from "pinia"; import {ref} from "vue"; export const UseCategoryItemsStore = defineStore('UseCategoryItemsStore', () => { const balanceCategories = ref([]) const totals = ref([]) function getBalanceItems() { axios.get(route('balance-item.index')).then((response) => { balanceCategories.value = response.data // console.log(balanceCategories.value) }) } function getTotals() { axios.get(route('balance-item.totals')).then((response) => totals.value = response.data) } function getData() { getTotals() getBalanceItems() } function updateBalanceItemsTotals(selectedItem) { balanceCategories.value.forEach((category) => { category.balance_items.forEach((item) => { if (item.id === selectedItem.id) { // item.total = item.count * item.amount console.log(item) } }) }) } getTotals() getBalanceItems() return {balanceCategories, totals, getBalanceItems, getTotals, getData, updateBalanceItemsTotals} }) 在此测试中,我执行“props.balanceItem.total = 500”。但如果我检查商店,它不会更新。看来将“balanceItem”分配给一个道具会失去与我的 Pinia 商店的反应性。我可以使用“form.total = form.count * form.amount”手动更新我的表单,但这对我来说似乎很老套,我想使用 Pinia 商店的反应性。我考虑过根据“BalanceItem”获取 Pina 项目,但这似乎也很棘手。谁知道为什么失去反应性? 我有laravel 10.39、vue3.2.41和pinia 2.1.17惯性0.6.11。到目前为止我知道的所有最新版本。 我像这样更新我的表格和商店: <script setup> import {useForm} from "@inertiajs/vue3"; import NumberInput from "@/Components/NumberInput.vue"; import {UseCategoryItemsStore} from "@/Stores/UseCategoryItemsStore.js"; const categoryItemStore = UseCategoryItemsStore() const props = defineProps({balanceItem: Object, errors: Object}) let item = categoryItemStore.getItemById(props.balanceItem); let form = useForm(item); const emit = defineEmits(['update-balance-item']) const submit = () => { form.post(route('balance-item.update'), { preserveScroll: true, onSuccess: () => { item = categoryItemStore.updateItem(form) form = useForm(item) emit('update-balance-item') } }) } </script> 我将此功能添加到我的商店: import {defineStore} from "pinia"; import {ref} from "vue"; export const UseCategoryItemsStore = defineStore('UseCategoryItemsStore', () => { const balanceCategories = ref([]) const totals = ref([]) function getBalanceItems() { axios.get(route('balance-item.index')).then((response) => { balanceCategories.value = response.data // console.log(balanceCategories.value) }) } function getItemById(item) { let category = balanceCategories.value.find((category) => { return category.id === item.item_category_id }) return category.balance_items.find((item_from_store) => { return item_from_store.id === item.id }) } function updateItem(form) { const item = getItemById(form) item.count = form.count item.amount = form.amount item.total = item.count * item.amount return item } function getTotals() { axios.get(route('balance-item.totals')).then((response) => totals.value = response.data) } function getData() { getTotals() getBalanceItems() } getTotals() getBalanceItems() return {balanceCategories, totals, getBalanceItems, getTotals, getData, getItemById, updateItem} }) 假设如果帖子获得 200,我的表单值可用于更新商店和更新表单。这是我能想到的最好的


如何使用 jinja2 在 Ansible 中加入引号?

我有一个ansible列表值: 主机= [“站点1”,“站点2”,“站点3”] 如果我尝试这个: 主持人 |加入(”, ”) 我得到: 站点 1、站点 2、站点 3 但我想得到: “站点1”、“站点2”、“站点3”


不支持的运算:Infinity 或 NaN toInt

从另一个页面启动幻灯片拼图项目时出错。 类 PuzzlePage 扩展 StatefulWidget { 最终 int 行、列; PuzzlePage({int 列 = 3, int 行 = 3}) :列 =


SQL:如何检索上一年的平均值?

我的数据集有问题 月 年 销售量 1 2021年 100 2 2021年 150 3 2021年 200 1 2022年 100 2 2022年 140 3 2022年 120 1 2023年 100 2 2023年 100 3 2023年 100 我想添加一个新列,例如...


C# 集合在删除然后添加元素后包含预期的自身

我收集了一些。 1 2 3 例如,当我删除 2 时,集合将变为 1,3。但是,当我去添加另一个项目时,列表变成 1 3 3 因为顺序是基本的...


如何决定torchsummary.summary(model=model.policy, input_size=(int, int, int))的'input_size'参数?

这是我的 CNN 网络,由“print(model.policy)”打印: CNN政策( (演员): 演员( (features_extractor): CustomCNN( (cnn): 顺序( (0): Conv2d(1, 32, kernel_size=(3, 3), st...


在 SQL Developer 上运行创建表学生时出错:CREATE TABLE Students

创建表学生( 年号(4) NOT NULL, 学期 VARCHAR2(1) NOT NULL CONSTRAINT Stu_sem_ck CHECK (学期 IN ('1', '2', '3')), 部门 VARCHAR2(3) NOT NULL, 课程编号...


创建一个bat文件,依次运行3个程序

你好,我有 3 个程序,我每天都会一一运行,我想创建一个 bat 文件来运行这 3 个 exe 文件,但我无法让它工作。 这是我的文件: @回声关闭 echo“开始音频” 圣...


DHCP响应中的giaddr字段和DHCP option 3有什么区别?

我有一个已经使用多年的 DHCP 客户端。到目前为止,它始终从 DHCP 选项 #3 获取其网关 IP 地址。现在使用不提供选项 3 的新 DHCP 服务器运行(是的,我...


Apss 脚本“if”条件评估不正确

oldnames[i+3]='汤姆' newnames[i]='汤姆' 当两个参数具有相同的值时(见上文),为什么我的代码会执行? 对于 (var i=0 ; i oldnames[i+3]='汤姆' newnames[i]='汤姆' 当两个参数具有相同的值(见上文)时,为什么我的代码会执行? for (var i=0 ; i<pocet2 ; i++) { var oldnaz=(oldnames[i+3]).toString(); var newnaz=(newnames[i]); oldnaz=oldnaz.toString(); newnaz=newnaz.toString(); //Logger.log("oldname = "+oldnaz); //Logger.log("newname = "+newnaz); if(newnames[i]=='' ) { //Logger.log(ss.getSheetByName(oldnames[i+3]).getSheetName()); //Logger.log(i); //Logger.log(i+3); ss.getSheetByName(oldnames[i+3]).setName((i+1).toString()); } ** else if(newnames[i] != oldnames[i+3]) { //Logger.log(newnames[i]); //Logger.log(oldnames[i+3]); ss.getSheetByName(oldnames[i+3]).setName(newnames[i]); }** else { //Nothing } } 我尝试对代码进行一些更改,但结果在各方面都是如此:条件为 TRUE。 但是当第一个值是 Tom 并且第二个值是 Tom 时,则 else if(Tom != Tom) 应该为 FALSE。 非常感谢您的提示。 如果 oldnames 和 newnames 来自使用 range.getValues() 的范围,则这两个变量都是二维数组而不是一维数组。 因此,oldnames[i+3]='Tom' newnames[i]='Tom'是假的,那就是 oldnames[i+3]=['Tom']; //array newnames[i]=['Tom']; /*<ignore>*/console.config({maximize:true,timeStamps:false,autoScroll:false});/*</ignore>*/ const newname=['Tom']; const oldname=['Tom']; console.log(newname != oldname);//expected true <!-- https://meta.stackoverflow.com/a/375985/ --> <script src="https://gh-canon.github.io/stack-snippet-console/console.min.js"></script> 两个数组无法进行比较。获取里面的字符串并比较: else if(newnames[i][0] != oldnames[i+3][0])


过去 3 个月收到的电子邮件总数

我有下表,需要查找每个客户发送的电子邮件的 3 个月滚动总数。 客户 ID 日期 邮件已发送 1 2023-06-30 2 1 2023-05-31 无效的 1 2023-04-30 3 1 2023-03-31 2 1 2...


如何使用 JavaScript 打印数组中的元素

我有一个包含元素的数组,例如 array = ["example1", "example2", "example3"]。 如何按以下格式打印? 示例 1 2. 示例 2 3. 示例 3...


`findall` 来自 Julia 中的笛卡尔索引向量

CI 是给定的向量。每个元素都是笛卡尔索引。 朱莉娅> CI 5 元素向量{CartesianIndex{3}}: 笛卡尔索引(1, 3, 1) ...


如何展平嵌套字典?

我有一个字典 富: A: AA1:1 AA2:2 乙: BB1:3 BB2:4 我想将其转换为: - {键:a,子键:aa1,值:1} - {键:a,子键:aa2,值:2} - {键:b,子键:bb1,值:3} - ...


主/细节防止细节组合

假设你有一个主表,其中有一些数据 主ID 主数据 -------- ---------- 1 数据1 2 数据2 3 数据3 以及引用主表的明细表


累积在列的每个单元格中输入的当前值和先前值

我想保存单个单元格的累加和。 例如: 如果在单元格 E2 中写了 3,我希望单元格 F2 保存值 3。 如果E2更改为2,则将旧值3添加到新值2并显示...


使用多个实例访问 SpringBoot 3/Hibernate 6 中的 Envers 修订版

在 SpringBoot 3 (Hibernate 6) 中,序列生成器现在分配多个增量。这也适用于 Envers 修订号。 隐式 seq 的默认值...


LeetCode 中无重复字符的最长子串

给定一个字符串 s,求最长不包含重复字符的子串的长度。 输入:s =“abcabcbb” 输出:3 解释:答案是“abc”,长度为3。 ...


对数组的每 N 个元素进行排序的排序算法

我正在寻找一种对数组的每个 N 元素进行排序的算法。 例如,数组为 7 8 6 4 5 1 4 3 5,N 为 3。 我希望排序后的数组为 6 7 8 1 4 5 3 4 5 请注意...


查找列中每 3 个值的中位数

我想要一行代码能够找到 Fin1 列中每 3 列值的中位数。例如,第一个值将为 1.54、5.08 和 5.26 中的 5.08。第二个将是 5.27...


如何在两种不同类型上使用 except?

我可以在两种相同的类型上使用 except() ,例如: var list1 = 新列表 { 1 , 2 , 3 , 5 , 9 }; var list2 = 新列表 { 4 , 3 , 9 }; var ExpectedList = list1.Except(list2);//结果: {...


Nuxt 3 项目无法找到 PWA 图标

开发工具错误 我目前正在尝试在我的 nuxt 3 项目中实现 PWA 功能,但我不断遇到这个问题:[Vue Router warn]: No match found for location with path "/icon_512x512...


Vuetify 3 V-Stepper 插槽接头

在 vuetify 3 中创建 v-stepper 本质上有两种方法。您可以使用属性或模板/槽。 我无法使用属性方法,因为由于某种原因,转换很混乱......


3 月 31 日之后 Azure 应用服务备份是否可用?

关于微软针对 azure 应用程序服务的声明,摘自此处 https://learn.microsoft.com/en-us/azure/app-service/manage-disaster-recovery “从 2025 年 3 月 31 日开始,Azure ...


Grails 4 升级

我正在从 grails 3 升级到 grails 4 但运行时出现以下错误 错误 org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - **************************


根据第2列值对第3列进行操作

我有这个文件 $猫测试.txt 49808830/ccs 9492 塔卡 3 175833950/ccs 971 ACCC 1 180422692/ccs 971 ACCC 10 110952448/ccs 9714 标签 2 117309969/ccs 9714 标签 4 119998610/ccs 9714 标签 5 17150946...


Python Networkx 检测循环/圆圈

给出以下示例: 是否有可能检测网络中的环路(I1、I2、I3、C6、C7、I5)? 我尝试过: simple_cycles → 它适用于 3 个节点,但不适用于超过 3 个节点。 我会...


使用递归创建单行号模式

编写一个打印出数字序列的递归方法。 printSequence(4) 打印 1 2 3 4 3 2 1 公开课练习{ 公共静态无效主(字符串[] args){ 打印序列(4); ...


如何创建位置层次结构

假设有一个表,其中混合了国家、城市、子城市等数据。例子: 名称 |编号 |父 ID 1) 英国 | 1 | 0; 2) 伦敦 | 2 | 1; 3) 南伦敦 | 3 | 2; 我明白了...


对数组进行排序。输入--> [3,4,5,1,2]预期输出--->[5,2,3,1,4]

输入:nums = [3, 4, 5, 1, 2] 输出:nums = [5, 2, 3, 1, 4] 解释:在此示例中,偶数 [4, 2] 位于位置 [1, 4]。 它们按升序排序并放置在...


Springboot 3 ManytoMany 请求有效负载正确序列化

我正在使用 Spring Boot 3、Java 21 Restful API 和带有 mysql 的 JPA,但在接收请求时遇到问题。 我正在处理与模型 User 和 Invoi 的多对多关系...


跨3列递归查询(OrderID、OriginalOrderID、GroupOrderID)

我有一个 SQL 表,其中特别包含 3 个感兴趣的列: 订单ID、原始订单ID、父订单ID 列的使用对于这个问题并不重要。尽管如此,OrderID 是...


比较两个向量之间的 NA 的 R 方法

我正在尝试比较两个向量的相同元素,例如下面的向量 a 和 b。 # 向量 a 和 b 一个<- c(1, 2, 3, NA) b <- c(1, 3, NA, NA) # compare for identity a == b ## [1] TRUE


© www.soinside.com 2019 - 2024. All rights reserved.