简体   繁体   English

如何使用项目提供程序 function 从 Bootstrap-Vue 异步更新 b 表中的项目?

[英]How do I update the items async in a b-table from Bootstrap-Vue reusing the items provider function?

I am using Bootstrap-Vue v2.0.0-rc.11 and I just cannot get my head around how to update the table content.我正在使用 Bootstrap-Vue v2.0.0-rc.11,但我无法理解如何更新表格内容。 I am sure it is trivial.我相信这是微不足道的。

I am pulling my content from a backend using an item provider function.我正在使用项目提供商 function 从后端提取我的内容。

        <b-table
                 :items="myProvider"
        >

The initial call works just fine with the following method.初始调用使用以下方法工作得很好。

export default {
    methods: {
        myProvider(ctx) {
            let promise = axios.get('/backend?currentPage=' + ctx.currentPage);

            return promise.then((response) => {
                return(response.items || []);
            });
        },

To duplicate a row item I open a modal to enter a new name.为了复制一个行项目,我打开一个模式来输入一个新名称。 I make a backend call for the duplication which works well.我对复制进行了后端调用,效果很好。 Now I want to refresh the content displayed in the table showing the new item.现在我想刷新显示新项目的表中显示的内容。 How do I do this?我该怎么做呢?

The easiest I can think of would be to call the item provider function (here: 'myProvider') again.我能想到的最简单的方法是再次调用项目提供者 function(此处为“myProvider”)。 I can do this from the modal but I cannot provide the correct parameter (here: 'ctx').我可以从模式中执行此操作,但我无法提供正确的参数(此处:“ctx”)。

Is there an event to trigger/emit to reissue the backend call?是否有事件触发/发出以重新发出后端调用?

I tried things like:我试过这样的事情:

this.$refs.nameOfTable.$forceUpdate()

this.$refs.nameOfTable.$emit('XXX') // XXX = placeholder for various events

Any hint is appreciated.任何提示表示赞赏。 Thank you.谢谢你。

It's hidden in the docs, but it's just a simple refresh() call on the table reference.它隐藏在文档中,但它只是对表引用的简单 refresh() 调用。

<b-table ref="table" ... ></b-table>
this.$refs.table.refresh();

From the Force refreshing of table data section of the docs .来自文档强制刷新表数据部分。

refresh is not worked now刷新现在不起作用

you can use 'key' attribute instead.您可以改用“键”属性。

<b-table key="key" ... ></b-table>

data() {
  return {
    key: 1
  }

this.key += 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 仅在应用过滤器时显示 bootstrap-vue b-table 中的项目 - Only display items in bootstrap-vue b-table when filter is applied Bootstrap-vue - 如何以编程方式显示/隐藏 b 表列 - Bootstrap-vue - How to show/hide a b-table column programmatically 如何在bootstrap-vue中的“ b-table”组件中使用插槽“ bottom-row”? - How to use the slot “bottom-row” in “b-table” component in bootstrap-vue? 如何使用“_showDetails”动态加载Bootstrap-vue“b-table”行数据? - How to load Bootstrap-vue "b-table" row data dynamically using "_showDetails"? bootstrap-vue b-table:在表重新加载时保持扩展行扩展 - bootstrap-vue b-table: keep expanded rows expanded on table reload 在bootstrap-vue中在没有jquery的情况下在b表中创建新的可编辑行 - Creating a new editable row in a b-table without jquery in bootstrap-vue 如何从自定义数据呈现的 bootstrap-vue 表中获取数据项数组 - How to get array of data items from custom data rendered bootstrap-vue table 将 BootstrapVue 与 Vue.Draggable 一起使用? 并将项目从列表中删除到 b 表? - using BootstrapVue with Vue.Draggable? and drop items from list to b-table? bootstrap vue b-table上模板内的Vue&#39;this&#39;对象 - Vue 'this' object inside template on bootstrap vue b-table Bootstrap Vue更改b表中每个单元格的背景 - Bootstrap Vue change background for each cell in b-table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM