javascript Dojo - 如何使用更新的 ItemFileReadStore 数据刷新组合框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6244305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 20:01:43  来源:igfitidea点击:

Dojo - How to refresh combobox with updated ItemFileReadStore data

javascripthtmlajaxdojo

提问by SIr Codealot

I changed ItemFileReadStore for combobox in Dojo. My code looks something like

我在 Dojo 中为组合框更改了 ItemFileReadStore。我的代码看起来像

    <span dojoType="dojo.data.ItemFileReadStore"
                jsId="comboStore"
                data="transformData">
            <select dojoType="mywidget.DropDown" id="transformCombo" value="" store="comboStore" searchAttr="name" name="state" maxHeight="100"/>

My widget is similar to dojo combobox widget. I changed transformData but the combobox is not updated until the page is entirely reloaded again. Any idea?

我的小部件类似于 dojo 组合框小部件。我更改了 transformData 但组合框在页面完全重新加载之前不会更新。任何的想法?

回答by Peter Gibson

If the content is changing server side and you just want to refresh your local copy of it without reloading the page, you can call fetchon the store and update your component when you receive the new data.

如果内容在服务器端发生变化,而您只想在不重新加载页面的情况下刷新它的本地副本,您可以fetch在收到新数据时调用商店并更新您的组件。

Here's the code that I use to refresh a dojox.grid.DataGrid when the server side content is updated:

这是我用来在服务器端内容更新时刷新 dojox.grid.DataGrid 的代码:

// initialise store and link to DataGrid
var store = new dojo.data.ItemFileReadStore({
    url: "items.json",
    clearOnClose: true,
    urlPreventCache: true
});
var grid = dijit.byId("grid")
grid.setStore(store);

// code to update local copy
store.close();
store.fetch({
    onComplete: function(items, request) {
        grid._refresh();
    }
});

If you are modifying the data client side, you should probably be using ItemFileWriteStore as Andrei suggested.

如果您正在修改数据客户端,您可能应该按照 Andrei 的建议使用 ItemFileWriteStore。

Edit: grid.sort()can be used for refreshing a DataGrid as an alternative to grid._refresh()(who's behaviour may change over time)

编辑: grid.sort()可用于刷新 DataGrid 作为替代grid._refresh()(谁的行为可能会随着时间的推移而改变)

回答by Andrei

How do you refresh the ItemFileReadStore? ItemFileReadStore - it's read-only datastore. In your case you should use ItemFileWriteStore. Look this question " dijit.form.filteringselect dynamically change options". I think that's what you're looking for.

你如何刷新 ItemFileReadStore?ItemFileReadStore - 它是只读数据存储。在您的情况下,您应该使用 ItemFileWriteStore。看看这个问题“ dijit.form.filteringselect 动态更改选项”。我想这就是你要找的。