将 dojo.xhrPost 中的数据源绑定到文本框以进行自动完成

发布于 2024-10-06 15:49:40 字数 925 浏览 0 评论 0原文

我继承了一个使用 Dojo 1.5 和模板工具包的 Web 应用程序。我很喜欢学习道场,但速度很慢。

最初,当打开我们的网络表单时,我们会在页面的右侧有一个文件列表,如下所示......

AAA_text
BBB_text_1
BBB_text_2
CCC_text
....
....

在左侧,我们有一个搜索框,询问要使用的文件子集。通常我们只需输入“AAA”,然后按下框下方的“搜索”键后,右侧的 div 就会找到匹配的文件并显示它们。

我们要做的是消除“搜索框”,并在键入“AAA”(或“BBB”或“CCC”, ETC)。

我想简而言之,这相当于在搜索框中键入每个键后按下“搜索”按钮。

这听起来是一个现实的目标,甚至是可能的吗?代码本身使用了大量的 Template Tookit,所以我不打算进行任何重大重写。

如果我没有说清楚,请告诉我。为了清楚起见,我可以详细说明。非常非常感谢!珍妮

编辑:好吧,到目前为止我已经解决了很多问题,事实证明,由于其中许多事情都有做的倾向,所以我真正需要的是得到清楚如何使自动完成工作。这就是说,我的文本框有一个数据源,但不太确定如何将其绑定到文本框。我有一个 dojo.xhrPost 例程可以处理获取值。

它看起来像这样......

 dijit.byId('files_matching').getValue(),

谷歌搜索道场自动完成示例给了我无数的链接,但没有一个被证明是有帮助的。所以我想我的问题已经转变为......
1.您甚至可以在纯文本框中使用自动完成功能吗(我见过链接说您只能在组合框中使用它)
2. 是否有一个链接详细描述/显示了如何使用 dojo.xhrPost 将 dojo 文本框绑定到数据源。
我已经很接近解决这个问题了,但我面前似乎仍然有一个巨大的鸿沟。

I inherited a web app that uses Dojo 1.5 and the template toolkit. I am enjoying learning dojo but it's at a slow pace.

Initially when bringing up our web form, we'll have a list of files on the right side of the page like so....

AAA_text
BBB_text_1
BBB_text_2
CCC_text
....
....

On the left side we have a search box that asks for the subset of file to use. Normally we would just type in "AAA" and then the div on the right side would find those files that match and display them after you press the "Search" key below the box.

What we are looking to do is to eliminate the "Search box" and have the list of files matching "AAA" to come up in the right side div as "AAA" is being typed, (or "BBB" or "CCC", etc).

I suppose in a nutshell it's the equivalent having the "Search" button pressed after every key is typed in the Search box.

Does this sound like a realistic goal or even possible? The code itself uses a ton of Template Tookit so I'm not looking to do any major rewrite.

If I am not making myself clear, let me know. I can elaborate for clarity. Many many thanks! Janie

EDIT: OK, I have solved a good deal of my problem so far and as it turns out, as so many of these things have a propensity to do, that what I am really needing is to get clear on how to make autocomplete work. Which is to say that I have a data source for my text box but not really sure how to tie it to the text box. I have a dojo.xhrPost routine that can handle grabbing the values.

It looks like this....

 dijit.byId('files_matching').getValue(),

Googling dojo autocomplete examples gives me a zillion links and none of which are proving helpful. So I suppose my questions have transitioned to....
1. Can you even use autocomplete on a mere text box (I've seen links that say that you can only use it on combo boxes)
2. Is there a link out there somewhere that describes/shows in detail how to tie a dojo text box to a data source using dojo.xhrPost.

I am so close to solving this and I still seem to have a gaping chasm in front of me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素染倾城色 2024-10-13 15:49:40

如果没有看到您的代码,很难确定,但如果您还没有代码,我建议您创建一个 ItemFileReadStore 或类似的东西来开始。这样,您就可以在客户端本地查询该存储,而无需在每次击键后收到服务器请求。

它可能看起来像这样:

var file_store = new dojo.data.ItemFileReadStore({ data: {
  items: [{ name:"AAA_text" },
          { name:"AAA_text_1" },
          { name:"BBB_text_2" }]
}});

当你准备好之后,你可以从文本输入的 onChange 事件中调用一个函数:

<input type="text" onchange="query_store(this.value);" />

然后你可以处理从 onchange 事件调用的函数中的实际查询:

var query_store = function(search_for) {

  var my_query = { name: search_for+"*" }; // * for wildcard match

  completed = function(items, result){
    for(var i = 0; i < items.length; i++){
      var value = file_store.getValue(items[i], "name");
      alert(value); // Instead of alert, you can save the values to your div.
    }
  };

  file_store.fetch({ query: my_query, onComplete: completed });
}

关于此的很多好信息可以是找到这里

希望这至少有一点帮助。

It's difficult to say for sure without seeing your code but if you don't have one already, I would recommend to create an ItemFileReadStore or something similar to start with. That way you can query that store locally on the client without having server requests after every key stroke.

It could look something like this:

var file_store = new dojo.data.ItemFileReadStore({ data: {
  items: [{ name:"AAA_text" },
          { name:"AAA_text_1" },
          { name:"BBB_text_2" }]
}});

When you have that in place you can call a function from your text input's onChange event:

<input type="text" onchange="query_store(this.value);" />

And then you handle to actual query from the function called from the onchange event:

var query_store = function(search_for) {

  var my_query = { name: search_for+"*" }; // * for wildcard match

  completed = function(items, result){
    for(var i = 0; i < items.length; i++){
      var value = file_store.getValue(items[i], "name");
      alert(value); // Instead of alert, you can save the values to your div.
    }
  };

  file_store.fetch({ query: my_query, onComplete: completed });
}

A lot of good information about this can be found here

Hope this is at least a little helpful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文