将数据从模板

时间:2018-01-19 09:53:11

标签: methods vue.js vuejs2 vue-component

我在visualforce页面的构建中使用了Vue.JS。

我有下面的Vue模板代码,我可以在页面上打印 acc.name 。但现在我需要将此值发送到Vue应用程序的方法部分中的 addtoterriotry 方法。

请在我的Vue应用程序组件下面找到。

<v-dialog v-model="addToTerr" max-width="1000">\
                    <v-card>\
                        <v-card-title class="headline">Review Selected Accounts</v-card-title>\
                        <v-card-text>\
                            <div v-for="acc in this.items" v-if="acc.selected">{{acc.Name}}</div>\
                        </v-card-text>\
                        <v-card-actions>\
                            <v-btn color="secondary" v-on:click="addToTerriotry">Add</v-btn>\
                            <v-btn v-on:click="addToTerr = false">Close</v-btn>\
                        </v-card-actions>\
                    </v-card>\
                </v-dialog>\

addtoterriotry方法:

   methods: {
                selectDeselectAccount: function (props) {
                    props.item.selected = props.item.selected ? false : true;
                    if (props.item.selected)
                        this.accountsSelected = this.accountsSelected + 1;
                    else
                        this.accountsSelected = this.accountsSelected - 1;
                },
                showaccount: function (props) {
                    this.selectedaccount = props.item;
                    this.accdetails = true;
                },
                addToTerriotry: function () {
                    alert('Invoke Controller Action');
                   // Fetch acc.name value here.
                     CallApexMethod();


                }

1 个答案:

答案 0 :(得分:0)

假设您的意思是尝试访问acc selected值为true的{​​{1}},只需在items数组的开头找到该元素即可。你的addToTerriotry方法:

addToTerriotry: function () {
  alert('Invoke Controller Action');
  let acc = this.items.find(i => i.selected);
  console.log(acc.name);  
  CallApexMethod();
}