小编use*_*711的帖子

JavaScript 检查字符串是否至少有三个字符在另一个变量中

我有一个变量activeUserName和一个变量manager1

如何检查是否activeUserName包含至少三个字符,在manager1?(这些字符的位置无关紧要)

例如在下面的例子中,它应该返回 true,因为字符 'J'、'o' 和 'e' 在里面manager1

var activeUserName = "JohnDoe100";
var manager1 = "JYZALoe999";
Run Code Online (Sandbox Code Playgroud)

现在我正在使用 indexOf 方法并且只查看某些位置的字符,这就是我想改变它的原因:

if (isEditor == false){
    if (((activeUserName.indexOf(manager1.charAt(0)) !== -1)  && (activeUserName.indexOf(manager1.charAt(2)) !== -1)) || (activeUserName.indexOf(manager1.charAt(4)) !== -1)){
        // doSth();
    } else if (((activeUserName.indexOf(manager2.charAt(0)) !== -1)  && (activeUserName.indexOf(manager2.charAt(2)) !== -1)) || (activeUserName.indexOf(manager2.charAt(4)) !== -1)){
        // doSth();
    } else {
        // doSth();
    }
}
Run Code Online (Sandbox Code Playgroud)

我读过 Regex,但我不确定这是否可以应用在这里。

任何帮助表示赞赏!

javascript string var character indexof

9
推荐指数
1
解决办法
1157
查看次数

Vue.js 挂载方法被调用两次

this.fillForm()我的 Vue 组件C (EditComment) 的方法被调用了两次,但我无法理解为什么。我尝试使用uuid,但不知道知道它beforeCreate被调用两次有什么帮助。

在此输入图像描述

有 3 个组件。以下是相关部分:

组分A

showCommentDialog: function(recordNumber) {
  this.$modal.show(
    ShowComment,
    {
      commentRecId: recordNumber
    },
    {
      draggable: true,
      width: 400,
      height: 250
    },
    {
      closed: function(event) {}
    }
  );
Run Code Online (Sandbox Code Playgroud)

组分B

    <EditComment v-bind:comment-rec-id="commentRecId" v-if="showEdit"></EditComment>
  </div>
</template>

<script>
import * as $ from "jquery";
import EditComment from "./EditComment.vue";


export default {
  props: ["commentRecId"],
  data: function() {
Run Code Online (Sandbox Code Playgroud)

有了这个功能

editItem: function(){
      this.showEdit = true;
      console.log("editItem function() called!");
      var playerID = this.$store.state.selectedPlayer.ID;

      this.$modal.show(
              EditComment, …
Run Code Online (Sandbox Code Playgroud)

javascript methods reference vue.js vue-component

4
推荐指数
1
解决办法
2万
查看次数