gpt4 book ai didi

javascript - 如何在 semantic-ui api 中显示结果

转载 作者:行者123 更新时间:2023-11-30 09:46:14 24 4
gpt4 key购买 nike

我对 semantic-ui api 有疑问我在多个选择元素上使用它从​​服务器检索项目这是我的 javascript 代码

$('select[name=problems]').dropdown('destroy').dropdown({
minCharacters: 3,
saveRemoteData: false,
apiSettings: {
on: 'change',
url: '/ajax/contest.getProblemQuery/',
method: 'post',
data: {
argv: {
page: 0,
limit: 1000
}
},
beforeSend: function (settings) {
settings.data.argv.q = settings.urlData.query;
return settings;
},
beforeXHR: function (xhr) {
console.log('xhr');
console.log(xhr);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.setRequestHeader('X-CSRFToken', $.cookie('csrftoken'));
return xhr;
},
onResponse: function (response) {
console.log('onresp');
if ( response != 'F' && response.length != 0 ) {
var list = {results: [], success: true};
for ( var i = 0; i < response.items.length; ++i ) {
list.results.push({
value: response.items[i][0],
name: response.items[i][1] + ' - ' + response.items[i][2],
text: response.items[i][1] + ' - ' + response.items[i][2]
});
}
return list;
}
else
return {success: false};
},
successTest: function (response) {
return response.success || false;
},
onComplete: function (response, element, xhr) {
// always called after XHR complete
},
onSuccess: function (response, element) {
console.log('suc');
console.log(response);
// valid response and response.success = true
},
onFailure: function (response, element) {
console.log('fail');
},
onError: function (errorMessage, element, xhr) {
// invalid response
},
onAbort: function (errorMessage, element, xhr) {
// navigated to a new page, CORS issue, or user canceled request
}
}
});

我的问题:

  1. 在我将“{query}”放入 url 之前它不会发送请求。
  2. 当它发送请求和接收数据时,所有数据都存储在浏览器 session 存储中。我将“saveRemoteData”设置为 false,但在每次请求后我检查了存储并在其中找到了新记录。
  3. 收到响应后,我将格式更改为sematic-ui.com/modules/dropdown.html#/examples [远程内容]但它没有显示下拉部分中的项目。

最佳答案

when it sends the request and receives the data, all data stores in browser session storage. i set 'saveRemoteData' to false but after each request i checked the storage and i found the new record on that.

可能是 API 的错误。我遇到了同样的问题,我在网上找不到解决办法。所以我写了自己的拼音。

HTML:

<div id="my_dropdown" class="ui multiple search selection dropdown select-city">
<input type="hidden" name="city"> <i class="dropdown icon"></i>
<div class="default text">Select city</div>
<div class="menu"></div>
</div>

和下拉列表中的 JS({}):

beforeSend: function(settings) {
/**
* minCharacters option doesn't work form me with dropdown,
* so I'm checking length manually and clear the search result in DOM
* and reject request if search string is too short
*/
if ($("#my_dropdown").find("input.search").val().length < 3) {
$("#my_dropdown").find(".menu.transition.visible").html("");
return false;
}
/**
* here I'm manually clearing the cache in localStorage
*/
if (typeof(Storage) !== "undefined") {
var sStorage = window.sessionStorage;
//console.log(sStorage.getItem("/my/request/url/"));
sStorage.removeItem("/my/request/url/");
}
/**
* some standard actions
*/
settings.data.str = $("#my_dropdown").find("input.search").val();
console.log(settings.data);
return settings;
}

看起来有点丑,但对我有用。

关于javascript - 如何在 semantic-ui api 中显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38828132/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com