Giter VIP home page Giter VIP logo

Comments (2)

TerryZ avatar TerryZ commented on May 30, 2024

Use v-model directive directly.

Some code for example below

<v-suggest
  show-field="name"
  v-model="userName"
  :data="list"
 >
</v-suggest>

<script>
export default {
  data () {
    return {
      list: [
        { name: 'tom' },
        { name: 'jerry' },
      ]
      userName = 'jerry'
    }
  }
}
</script>

from v-suggest.

tikvarova avatar tikvarova commented on May 30, 2024

Dear Terry,

Thanks for the answer, but what will be the proper solution if we need to set "row", not only "text". For example at the moment I use wrapper component which holds v-suggest. I use props to set list items and current object:

The list contains data in simmilar format:


// List object is similar to:
{
  id: 1, name: "test1",
  id: 2, name: "test2",
  id: 3, name: "test3",
  id: 4, name: "test4",
  ...
  ...
  ...
}

Then in wrapper component I use some parameters like:

ref="suggested" :key-field="keyField" :data="list" @values="values" @clear="$emit('clear')" :show-field="showField":full-list="true" etc.

and than use something like this:


 <script>
export default {
  props: {
    list: { type: [Object, Array], required: true }, 
    current: { type: [Object, Array], required: true },
    v: { type: String, default: '' },
    t: { type: String, default: '' },
  },
  data() {
    return {
      keyField: 'id',
    };
  },
  mounted: function() {
    this.$nextTick(() => {
      this.$refs.suggested.text = this.current[this.t] ? this.current[this.t] : '';
    });
  },
  methods: {
    values(row) {
      this.$emit('values', row);
    },
    clearText() {
      console.log('Cleared from BranchNew "clear" method!');
    },
    showField(row) {
      return row.Name;
    },
  },

It works, but I want to check if there is better way to do this!

Thanks in advance

from v-suggest.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.