我正在使用 Materialize CSS 創建一個鏈接到我們公司的 Google Drive 的 Google Web App,用于一些基本的檔案流程流程。I am trying to create an autocomplete text field that when a user begins typing the name it populates options and when an option is selected it triggers the onAutocomplete callback and autofills some following fields based off of the client selected. 使欄位自動完成沒問題,但我無法觸發 onAutocomplete 回呼。
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link href="https://fonts.googleapis.com/icon?family=Material Icons" rel="stylesheet">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<?!= include("pageCSS"); ?>
</head>
<body>
<div >
<input type="text" id="autocompleteField"/>
<label for="infoModalName">Client Name</label>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js">
</script>
<?!= include("pageScripts"); ?>
</body>
</html>
<script>
function populateWords(words){
//console.log(words)
var autoComplete = document.getElementById("autocompleteField");
M.Autocomplete.init(autoComplete, {data: words}, {onAutocomplete: function()
{console.log("Hello")}});
}
</script>
現在,我只是想讓回呼函式輸出任何內容,而不是寫入其他欄位。許多在線檔案都使用 JQuery 設定,但這是我需要開始作業的最后一件事,到目前為止我還沒有使用任何 JQuery,所以如果可能的話,我寧愿堅持使用 Javascript 解決方案。
uj5u.com熱心網友回復:
似乎 的論點M.Autocomplete.init就像M.Autocomplete.init(elems, options)。Ref而且,似乎words需要一個物件的值。當這些反映在你的腳本中時,它變成如下。
修改后的腳本:
在本次修改中,請populateWords進行如下修改。
function populateWords(words){
words = {key: "value"}; // This is a sample value for testing this modification.
var autoComplete = document.getElementById("autocompleteField");
M.Autocomplete.init(autoComplete, {data: words, onAutocomplete: function() {console.log("Hello")}});
}
- 在這個修改中,當
k被放入文本輸入時,自動完成運行,當key被選擇時,console.log("Hello")運行。
筆記:
- 不幸的是,根據您的問題,我無法知道
words您腳本中的價值。所以我使用了一個樣本值。請根據您的實際情況進行修改。
參考:
- 自動完成
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/348858.html
標籤:javascript 谷歌应用程序脚本 物化
上一篇:創建父檔案夾時創建子檔案夾
