我正在爲我工作的公司的web應用程序工作,我有一個需要的窗體的問題。jquery - xeditable選擇源使用函數,使用緩存和本地存儲(indexedDB)
我在使用xeditable填充使用不同函數的數據的選擇列表時遇到了一些麻煩。
問題是正在執行的代碼填充選擇框不等待其他函數從本地存儲獲取數據並返回它,即使我使用的是緩存的(我不確定是否我正確使用了緩存/解析功能)。
這是我的代碼:
<a id="TypeID" data-type="select" data-pk="1966_TypeID" data-original-title="Please Select" data-pid="36" class="editable editable-click">3609</a>
的jQuery:
function popSelectBox(PID) {
var rtn = [];
$.indexedDB('testDatabase').objectStore('Lookup').index('PID').each(function (i) {
var source = {};
source.value = i.value.ID;
source.text = i.value.Name;
rtn.push(source);
}, PID).done(function (r, e) {
console.log(rtn);
console.log('popSelectBox function (I expect to see this first) - This section should complete before the makeEditable function');
return rtn;
});
}
function makeEditable() {
$('.editable').editable({
validate: function (value) {
if ($.trim(value) === '') {
return 'This field is required';
}
return false;
},
success: function (response, newValue) {
console.log($(this).data('pk'), newValue);
//$(this).parent().css('background-color', 'green');
},
/**** this is the problem section of this function ****/
source: function() {
//if the type is a select list then we need to populate it, this is done here
if ($(this).data('type') === 'select') {
var d = $.Deferred();
$.when(d).done(function (v) {
console.log(v);
return v;
});
d.resolve(popSelectBox($(this).data('pid').toString()));
console.log('makeEditable function (I expect to see this last) - This section should wait for the popSelectBox function to finish');
}
}
});
}
我也有一個小提琴這裏http://jsfiddle.net/f8otrayn/3/,顯示上方。 這個小提琴中包含一個本地存儲設置的例子,我設置了這個函數,但是我已經註釋掉了函數調用,你可以檢查代碼並取消註釋,如果你願意的話。
我正在尋找一種方法來等待,直到popSelectBox函數完成並返回數據,以便我可以使用該數據填充選擇框,我真的不想使用setTimeout,因爲有很多本地條目所以等待一段特定時間的存儲可能無法在所有情況下工作。
沒有人有任何想法
感謝
你好,這是十分感謝,它返回我們想要的東西,但是它不填充選擇框。 已經放置了幾個遊戲機以查看發生了什麼,看起來arr不在可編輯的功能範圍內,這很奇怪。 我不太確定它在做什麼,但在源代碼函數中添加控制檯不會返回任何東西,直到我單擊該元素,然後返回undefined。添加控制檯的上方或下方.editable功能回到我們所期望的 的PID在popSelectBox功能是IndexedDB的功能,我們有,它就像一個WHERE語句在SQL – 2014-11-04 12:32:31
是'有史以來popSelectBox'調用,並承諾得到解決? – 2014-11-04 13:19:24
並且做任何非選擇變得可編輯? – 2014-11-04 13:25:52