vue.js自动完成的下拉菜单在v-for内部不会渲染。

huangapple go评论74阅读模式
英文:

vue.js dropdown of autocomplete doesn't render when inside of a v-for

问题

以下是您要求的代码部分的中文翻译:

[![页面截图](https://i.stack.imgur.com/th353.png)](https://i.stack.imgur.com/th353.png)

我对Vue不太熟悉,而这个项目使用的是Vue 2.6.10。

我们有一个专有的控件,基本上是一个网络用户查找工具。

我加入了这个已经存在的项目。它是使用template.html文件和它们各自的.js文件构建的。

我有一个特定的模板文件,在其中我需要在v-for中使用我的查找控件。但我无法使下拉菜单在v-for内部呈现。如果我去掉v-for并硬编码控件(作为测试),查找下拉菜单可以正常呈现。

请看我的两个代码版本,一个是可以工作的硬编码版本,另一个是v-for版本,搜索名称后无法呈现我的下拉菜单。

我注意到两个版本之间的一个区别是,当下拉菜单正常呈现时,输入控件的类中包含了"ui-autocomplete-input",并且还包含了"autocomplete="off""。但在控件不按预期工作时,输入控件中没有这两个项。

工作版本:

```html
<template id="email-template">
    <div class="container border col-md-12" style="margin-top:10px;">
        <tabs style="padding-top:10px;">
            <tab title="任务摘要"&gt:
                <!-- 省略部分内容 -->
            &lt;/tab&gt;

            &lt;!-- 调查电子邮件设置 --&gt;
            &lt;tab title=&quot;调查&quot;&gt;
                <!-- 省略部分内容 -->
            &lt;/tab&gt;
        &lt;/tabs&gt;
    &lt;/div&gt;
&lt;/template&gt;

&lt;style scoped&gt;
    .emailGroup-header {
        cursor: pointer;
    }

        .emailGroup-header:hover {
            background-color: #E7E7E7;
        }
&lt;/style&gt;

不工作的v-for版本:

&lt;template id=&quot;email-template&quot;&gt;
    &lt;div class=&quot;container border col-md-12&quot; style=&quot;margin-top:10px;&quot;&gt;
        &lt;tabs style=&quot;padding-top:10px;&quot;&gt;
            &lt;tab title=&quot;任务摘要&quot;&gt;
                <!-- 省略部分内容 -->
            &lt;/tab&gt;

            &lt;!-- 调查电子邮件设置 --&gt;
            &lt;tab title=&quot;调查&quot;&gt;
                <!-- 省略部分内容 -->
            &lt;/tab&gt;
        &lt;/tabs&gt;
    &lt;/div&gt;
&lt;/template&gt;

&lt;style scoped&gt;
    .emailGroup-header {
        cursor: pointer;
    }

        .emailGroup-header:hover {
            background-color: #E7E7E7;
        }
&lt;/style&gt;

email.js 文件:

var emailPanel = Vue.component('email-panel', {
    props: {
    //    id: {
    //        type: Number,
    //    },
    //    emailGroupMembersAllList: {
    //        type: Object
    //    },
    //    autoIncludeEmails: {
    //        type: Object
    //    },
    },

    data() {
        return {
            opened: [],
            emailGroupMembersAllList: [],
        }
    },
    template: '#email-template',
    beforeMount() {
        window.addEventListener("beforeunload", this.handlerClose);
    },
    beforeDestroy() {
        window.removeEventListener("beforeunload", this.handlerClose);
    },
    mounted() {
        $(".userForm").nedLookup();

        this.getEmails();
    },
    computed: {
    },
    methods: {
        getEmails() {
            var vm = this;

            //获取电子邮件(包括此页面的当前用户)并填充GroupLists/to/cc/Subject
            this.getTaskSummaryEmails()
                .then(data => {
                    vm.emailGroupMembersAllList = data.EmailGroupMembersAllList;
                    vm.autoIncludeEmails = data.AutoIncludeEmails;
                    localStorage.setItem('data', JSON.stringify(data));
                })
                .catch(function (error) {
                    console.log(error);
                });
        },
        async getTaskSummaryEmails() {
            try {
                let resp;
                resp = await axios.get(`/api/task/email`);
                return resp.data;
            } catch (error) {
                console.log(error);
                this.$toasted.show("检索电子邮件组时出错", { type: "error", duration: 3000 })
            }
        },
        addNewEmailGroup() {
        },

        toggleEmailGroup(id) {
            const index = this.opened.indexOf(id);
            if (index > -1) {
                this.opened.splice(index, 1)
            } else {
                this.opened.push(id)
            }
        },

        tabChanged() {
            if (this.$toasted != null) {
                this.$toasted.clear();
            }
        },

        handlerClose(e) {
            if (this.$toasted != null) {
                this.$toasted.clear();
            }
        },
    }
})

希望这些翻译有助于解决您的问题。如果您需要进一步的帮助,请随时提出。

英文:

vue.js自动完成的下拉菜单在v-for内部不会渲染。

New to vue, and this particular project is using vue 2.6.10.

We have a proprietary control that we use which is basically a network user lookup.

I came on to this already established project. It is built using template.html files and their respective .js files.

I have this particular template file where I need a v-for with my lookup control inside. I cannot get the dropdown to render when it is inside of the v-for. If I take out the v-for and hardcode the controls (as a test), the lookup dropdowns render fine.

Please see my two versions of the code, the hardcoded one which works, and the v-for version that does not render my dropdown after a search by name.

One thing I have noticed that is a difference between the 2 versions, is that when I inspect my elements, I see that when the dropdown does render properly, the input control has ui-autocomplete-input as part of the class and also has autocomplete="off". When the control does not work as expected, those two items don't exist in the input control.

Working version:

&lt;template id=&quot;email-template&quot;&gt;
&lt;div class=&quot;container border col-md-12&quot; style=&quot;margin-top:10px;&quot;&gt;
&lt;tabs style=&quot;padding-top:10px;&quot;&gt;
&lt;tab title=&quot;Task Summary&quot;&gt;
&lt;table class=&quot;table userForm&quot;&gt; &lt;!--class userForm must be here for nedLookup!!--&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Email Groups&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td class=&quot;col-md-5&quot;&gt;
&lt;table class=&quot;table table-striped table-condensed table-bordered&quot;&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&quot;width: 10%&quot;&gt;Group1 Members&lt;/th&gt;
&lt;th style=&quot;width: 10%; text-align: center;&quot;&gt;AutoInclude&lt;/th&gt;
&lt;th style=&quot;width: 10%; text-align: center;&quot;&gt;Delete&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tr&gt;
&lt;td&gt;user1@test.com&lt;/td&gt;
&lt;td&gt;
&lt;span style=&#39;display: block; text-align: center; padding-top: 0;&#39;&gt;
&lt;label class=&quot;label&quot; style=&#39;margin-left: 0&#39;&gt;
&lt;input type=&quot;checkbox&quot; style=&#39;margin-left: 0&#39; checked&gt;
&lt;/label&gt;
&lt;/span&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;span style=&#39;display: block; text-align: center; padding-top: 0;&#39; class=&#39;trash-icon&#39;&gt;
&lt;i class=&#39;fa fa-trash&#39; style=&#39;margin-left: 0&#39;&gt;&lt;/i&gt;
&lt;/span&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;user2@test.com&lt;/td&gt;
&lt;td&gt;
&lt;span style=&#39;display: block; text-align: center; padding-top: 0;&#39;&gt;
&lt;label class=&quot;label&quot; style=&#39;margin-left: 0&#39;&gt;
&lt;input type=&quot;checkbox&quot; style=&#39;margin-left: 0&#39;&gt;
&lt;/label&gt;
&lt;/span&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;span style=&#39;display: block; text-align: center; padding-top: 0;&#39; class=&#39;trash-icon&#39;&gt;
&lt;i class=&#39;fa fa-trash&#39; style=&#39;margin-left: 0&#39;&gt;&lt;/i&gt;
&lt;/span&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;label&gt;&lt;input type=&quot;checkbox&quot; name=&quot;checkbox&quot;&gt; AutoInclude Entire Group&lt;/label&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;td class=&quot;col-md-4&quot;&gt;
&lt;input type=&quot;text&quot; :id=&quot;Group1_userLookup&quot;
:name=&quot;Group1_userLookup&quot; value=&quot;&quot;
class=&quot;nedLookup form-control&quot;
placeholder=&quot;Search User by Last Name, FirstName&quot; /&gt;
&lt;!--&lt;input id=&quot;userLookupEmail&quot; type=&quot;hidden&quot; data-ned=&quot;Email&quot; /&gt;--&gt;
&lt;/td&gt;
&lt;td class=&quot;col-md-2&quot;&gt;
&lt;button type=&quot;button&quot; class=&quot;btn btn-primary&quot; @click=&quot;addUserToGroup()&quot; role=&quot;button&quot;&gt;
Add User to Group
&lt;/button&gt;
&lt;/td&gt;
&lt;td class=&quot;col-md-1&quot;&gt;
&lt;button type=&quot;button&quot; class=&quot;btn btn-primary&quot; @click=&quot;saveGroup()&quot; role=&quot;button&quot;&gt;
Save Group
&lt;/button&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td class=&quot;col-md-5&quot;&gt;
&lt;table class=&quot;table table-striped table-condensed table-bordered&quot;&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&quot;width: 10%&quot;&gt;Group2 Members&lt;/th&gt;
&lt;th style=&quot;width: 10%; text-align: center;&quot;&gt;AutoInclude&lt;/th&gt;
&lt;th style=&quot;width: 10%; text-align: center;&quot;&gt;Delete&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tr&gt;
&lt;td&gt;user3@test.com&lt;/td&gt;
&lt;td&gt;
&lt;span style=&#39;display: block; text-align: center; padding-top: 0;&#39;&gt;
&lt;label class=&quot;label&quot; style=&#39;margin-left: 0&#39;&gt;
&lt;input type=&quot;checkbox&quot; style=&#39;margin-left: 0&#39;&gt;
&lt;/label&gt;
&lt;/span&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;span style=&#39;display: block; text-align: center; padding-top: 0;&#39; class=&#39;trash-icon&#39;&gt;
&lt;i class=&#39;fa fa-trash&#39; style=&#39;margin-left: 0&#39;&gt;&lt;/i&gt;
&lt;/span&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;3&quot;&gt;&lt;label&gt;&lt;input type=&quot;checkbox&quot; name=&quot;checkbox&quot;&gt; AutoInclude Entire Group&lt;/label&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;td class=&quot;col-md-4&quot;&gt;
&lt;input type=&quot;text&quot; :id=&quot;Group2_userLookup&quot;
:name=&quot;Group2_userLookup&quot; value=&quot;&quot;
class=&quot;nedLookup form-control&quot;
placeholder=&quot;Search User by Last Name, FirstName&quot; /&gt;
&lt;input id=&quot;userLookupEmail&quot; type=&quot;hidden&quot; data-ned=&quot;Email&quot; /&gt;
&lt;/td&gt;
&lt;td class=&quot;col-md-2&quot;&gt;
&lt;button type=&quot;button&quot; class=&quot;btn btn-primary&quot; @click=&quot;addUserToGroup()&quot; role=&quot;button&quot;&gt;
Add User to Group
&lt;/button&gt;
&lt;/td&gt;
&lt;td class=&quot;col-md-1&quot;&gt;
&lt;button type=&quot;button&quot; class=&quot;btn btn-primary&quot; @click=&quot;saveGroup()&quot; role=&quot;button&quot;&gt;
Save Group
&lt;/button&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;div class=&quot;text-center&quot;&gt;
&lt;btn type=&quot;button&quot; class=&quot;btn btn-primary&quot; @click=&quot;addNewEmailGroup&quot; role=&quot;button&quot;&gt;&lt;i class=&quot;fa fa-plus-circle&quot;&gt;&lt;/i&gt; Add Email Group &lt;/btn&gt;
&lt;/div&gt;
&lt;/tab&gt;
&lt;!-- Survey Email settings--&gt;
&lt;tab title=&quot;Survey&quot;&gt;
&lt;table class=&quot;table&quot;&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Coming Soon&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/tab&gt;
&lt;/tabs&gt;
&lt;/div&gt;
&lt;/template&gt;
&lt;style scoped&gt;
.emailGroup-header {
cursor: pointer;
}
.emailGroup-header:hover {
background-color: #E7E7E7;
}
&lt;/style&gt;

Non working version with v-for:

&lt;template id=&quot;email-template&quot;&gt;
&lt;div class=&quot;container border col-md-12&quot; style=&quot;margin-top:10px;&quot;&gt;
&lt;tabs style=&quot;padding-top:10px;&quot;&gt;
&lt;tab title=&quot;Task Summary&quot;&gt;
&lt;table class=&quot;table userForm&quot;&gt; &lt;!--class userForm must be here for nedLookup!!--&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Email Groups&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr v-for=&quot;emailGroupMembers in emailGroupMembersAllList&quot;&gt;
&lt;td&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td class=&quot;col-md-4&quot;&gt;
&lt;table class=&quot;table table-striped table-condensed table-bordered&quot;&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&quot;width: 10%&quot;&gt;{{emailGroupMembers.EmailGroup.GroupName}} Members&lt;/th&gt;
&lt;th style=&quot;width: 10%; text-align: center;&quot;&gt;AutoInclude&lt;/th&gt;
&lt;th style=&quot;width: 10%; text-align: center;&quot;&gt;Delete&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tr v-for=&quot;user in emailGroupMembers.EmailGroup.EmailGroupUsers&quot;&gt;
&lt;td&gt;{{user.Email}}&lt;/td&gt;
&lt;td&gt;
&lt;span style=&#39;display: block; text-align: center; padding-top: 0;&#39;&gt;
&lt;label class=&quot;label&quot; style=&#39;margin-left: 0&#39;&gt;
&lt;input type=&quot;checkbox&quot; style=&#39;margin-left: 0&#39; checked&gt;
&lt;/label&gt;
&lt;/span&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;span style=&#39;display: block; text-align: center; padding-top: 0;&#39; class=&#39;trash-icon&#39;&gt;
&lt;i class=&#39;fa fa-trash&#39; style=&#39;margin-left: 0&#39;&gt;&lt;/i&gt;
&lt;/span&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;td class=&quot;col-md-4&quot;&gt;
&lt;input type=&quot;text&quot; :id=&quot;emailGroupMembers.EmailGroup.GroupName + &#39;_userLookup&#39;&quot;
:name=&quot;emailGroupMembers.EmailGroup.GroupName + &#39;_userLookup&#39;&quot; value=&quot;&quot;
class=&quot;nedLookup form-control&quot;
placeholder=&quot;Last Name, FirstName&quot; /&gt;
&lt;!--&lt;input id=&quot;userLookupEmail&quot; type=&quot;hidden&quot; data-ned=&quot;Email&quot; /&gt;--&gt;
&lt;/td&gt;
&lt;td class=&quot;col-md-2&quot;&gt;
&lt;button type=&quot;button&quot; class=&quot;btn btn-primary&quot; @click=&quot;addUserToGroup()&quot; role=&quot;button&quot;&gt;
Add User to Group
&lt;/button&gt;
&lt;/td&gt;
&lt;td class=&quot;col-md-2&quot;&gt;
&lt;button type=&quot;button&quot; class=&quot;btn btn-primary&quot; @click=&quot;saveGroup()&quot; role=&quot;button&quot;&gt;
Save Group
&lt;/button&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;!--&lt;tr&gt;
&lt;td&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td class=&quot;col-md-4&quot;&gt;
&lt;table class=&quot;table table-striped table-condensed table-bordered&quot;&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&quot;width: 10%&quot;&gt;Group2 Members&lt;/th&gt;
&lt;th style=&quot;width: 10%; text-align: center;&quot;&gt;AutoInclude&lt;/th&gt;
&lt;th style=&quot;width: 10%; text-align: center;&quot;&gt;Delete&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tr&gt;
&lt;td&gt;karrie.klein@saic.com&lt;/td&gt;
&lt;td&gt;
&lt;span style=&#39;display: block; text-align: center; padding-top: 0;&#39;&gt;
&lt;label class=&quot;label&quot; style=&#39;margin-left: 0&#39;&gt;
&lt;input type=&quot;checkbox&quot; style=&#39;margin-left: 0&#39;&gt;
&lt;/label&gt;
&lt;/span&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;span style=&#39;display: block; text-align: center; padding-top: 0;&#39; class=&#39;trash-icon&#39;&gt;
&lt;i class=&#39;fa fa-trash&#39; style=&#39;margin-left: 0&#39;&gt;&lt;/i&gt;
&lt;/span&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;td class=&quot;col-md-4&quot;&gt;
&lt;input type=&quot;text&quot; :id=&quot;Group2_userLookup&quot;
:name=&quot;Group2_userLookup&quot; value=&quot;&quot;
class=&quot;nedLookup form-control&quot;
placeholder=&quot;Last Name, FirstName&quot; /&gt;
&lt;input id=&quot;userLookupEmail&quot; type=&quot;hidden&quot; data-ned=&quot;Email&quot; /&gt;
&lt;/td&gt;
&lt;td class=&quot;col-md-2&quot;&gt;
&lt;button type=&quot;button&quot; class=&quot;btn btn-primary&quot; @click=&quot;addUserToGroup()&quot; role=&quot;button&quot;&gt;
Add User to Group
&lt;/button&gt;
&lt;/td&gt;
&lt;td class=&quot;col-md-2&quot;&gt;
&lt;button type=&quot;button&quot; class=&quot;btn btn-primary&quot; @click=&quot;saveGroup()&quot; role=&quot;button&quot;&gt;
Save Group
&lt;/button&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;/tr&gt;--&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;div class=&quot;text-center&quot;&gt;
&lt;btn type=&quot;button&quot; class=&quot;btn btn-primary&quot; @click=&quot;addNewEmailGroup&quot; role=&quot;button&quot;&gt;&lt;i class=&quot;fa fa-plus-circle&quot;&gt;&lt;/i&gt; Add Email Group &lt;/btn&gt;
&lt;/div&gt;
&lt;/tab&gt;
&lt;!-- Survey Email settings--&gt;
&lt;tab title=&quot;Survey&quot;&gt;
&lt;table class=&quot;table&quot;&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Coming Soon&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/tab&gt;
&lt;/tabs&gt;
&lt;/div&gt;
&lt;/template&gt;
&lt;style scoped&gt;
.emailGroup-header {
cursor: pointer;
}
.emailGroup-header:hover {
background-color: #E7E7E7;
}
&lt;/style&gt;

email.js file:

var emailPanel = Vue.component(&#39;email-panel&#39;, {
props: {
//    id: {
//        type: Number,
//    },
//    emailGroupMembersAllList: {
//        type: Object
//    },
//    autoIncludeEmails: {
//        type: Object
//    },
},
data() {
return {
opened: [],
emailGroupMembersAllList: [],
}
},
template: &#39;#email-template&#39;,
beforeMount() {
window.addEventListener(&quot;beforeunload&quot;, this.handlerClose);
},
beforeDestroy() {
window.removeEventListener(&quot;beforeunload&quot;, this.handlerClose);
},
mounted() {
$(&quot;.userForm&quot;).nedLookup();
this.getEmails();
},
computed: {
},
methods: {
getEmails() {
var vm = this;
//go get emails (including current user of this page) and fill GroupLists/to/cc/Subject
this.getTaskSummaryEmails()
.then(data =&gt; {
vm.emailGroupMembersAllList = data.EmailGroupMembersAllList;
vm.autoIncludeEmails = data.AutoIncludeEmails;
localStorage.setItem(&#39;data&#39;, JSON.stringify(data));
})
.catch(function (error) {
console.log(error);
});
},
async getTaskSummaryEmails() {
try {
let resp;
resp = await axios.get(`/api/task/email`);
return resp.data;
} catch (error) {
console.log(error);
this.$toasted.show(&quot;There was an error retrieving the email groups&quot;, { type: &quot;error&quot;, duration: 3000 })
}
},
addNewEmailGroup() {
},
toggleEmailGroup(id) {
const index = this.opened.indexOf(id);
if (index &gt; -1) {
this.opened.splice(index, 1)
} else {
this.opened.push(id)
}
},
tabChanged() {
if (this.$toasted != null) {
this.$toasted.clear();
}
},
handlerClose(e) {
if (this.$toasted != null) {
this.$toasted.clear();
}
},
}
})

I have searched and not found anything matching my particular issue with this old version of vue.js

I have found suggestions regarding using the :key. I am not moving things around, so I don't believe I need the :key, but I tried it anyway to no avail.

答案1

得分: 0

我觉得你在这行缺少了`key`

```vuejs
&lt;tr v-for=&quot;emailGroupMembers in emailGroupMembersAllList&quot;&gt;

尝试:

&lt;tr v-for=&quot;(emailGroupMembers, index) in emailGroupMembersAllList&quot; :key=&quot;index&quot;&gt;
英文:

I think you're missing the key on this line:

&lt;tr v-for=&quot;emailGroupMembers in emailGroupMembersAllList&quot;&gt;

Try:

&lt;tr v-for=&quot;(emailGroupMembers, index) in emailGroupMembersAllList&quot; :key=&quot;index&quot;&gt;

答案2

得分: 0

我只会翻译代码的部分,以下是翻译后的代码:

Well, just going back to basics, I added an eventhandler for an outer static element and that solved the issue.

mounted() {
    this.getEmails();

    // 在这里为我们动态添加的nedLookups创建事件代理
    // 必须为已经存在于DOM中且包含我们的nedLookup的元素添加事件监听器
    document.getElementById("emailGroupsTable").addEventListener("click", function (e) { 
        if (e.target.nodeName == 'INPUT') { // 这是一个nedLookup元素
            $(".userForm").nedLookup();
        }
    });
},

希望这有所帮助。如果您需要进一步的翻译或有其他问题,请随时提出。

英文:

Well, just going back to basics, I added an eventhandler for an outer static element and that solved the issue.

    mounted() {
this.getEmails();
//Creating event delegate here for our dynamically added nedLookups
//have to add event listener to element that is already in the DOM and that contains our nedLookup
document.getElementById(&quot;emailGroupsTable&quot;).addEventListener(&quot;click&quot;, function (e) { 
if (e.target.nodeName == &#39;INPUT&#39;) { //this is one of the nedLookup elements
$(&quot;.userForm&quot;).nedLookup();
}
});
},

huangapple
  • 本文由 发表于 2023年7月13日 19:18:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76678764.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定