gpt4 book ai didi

angularjs - 更改 Angular Material 中 md-autocomplete 中的选定值

转载 作者:行者123 更新时间:2023-12-01 10:34:17 26 4
gpt4 key购买 nike

我在我的页面中使用了 md-autocomplete,现在我需要编辑一条记录,如何以编程方式更改 md-autocomplete 中的选定值?

这是 Angular 代码:

app.controller('DemoCtrl', DemoCtrl);
function DemoCtrl($timeout, $q, $log) {
var self = this;
self.simulateQuery = false;
self.isDisabled = false;
self.states = loadAll();
self.querySearch = querySearch;

function querySearch(query) {
var results = query ? self.states.filter(createFilterFor(query)) : self.states,
deferred;
if (self.simulateQuery) {
deferred = $q.defer();
$timeout(function () {
deferred.resolve(results);
}, Math.random() * 1000, false);
return deferred.promise;
} else {
return results;
}
}
function createFilterFor(query) {
var lowercaseQuery = angular.lowercase(query);
return function filterFn(state) {
return (state.value.indexOf(lowercaseQuery) != -1);
};
}
function loadAll() {
return totlaTablaeau.map(function (repo) {
repo.value = repo.address.toLowerCase();
return repo;
});

}
};

最佳答案

这是一个 CodePen使用在线文档示例。您只需要设置 md-selected-item 的值.

标记

<md-autocomplete ... md-selected-item="ctrl.selectedItem" ...></md-autocomplete>

...
<md-button class="md-raised md-primary" ng-click="ctrl.selectArkansas()">Select Arkansas</md-button>

JS
self.selectArkansas = function() {
self.selectedItem = {
value: "Arkansas".toLowerCase(),
display: "Arkansas"
};
}

关于angularjs - 更改 Angular Material 中 md-autocomplete 中的选定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38351726/

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