Javascript md自动完成不返回所选项目
我已经在Angular.js网站上实现了md自动完成。搜索和选择工作,它会更新显示的列表和所有内容。但由于某些原因,我无法阅读所选项目。无论我如何定义我的md所选项目,它都将始终保持Javascript md自动完成不返回所选项目,javascript,jquery,angularjs,angular-material,Javascript,Jquery,Angularjs,Angular Material,我已经在Angular.js网站上实现了md自动完成。搜索和选择工作,它会更新显示的列表和所有内容。但由于某些原因,我无法阅读所选项目。无论我如何定义我的md所选项目,它都将始终保持null。selectItem(item)中的项和范围中的值都不会更改 角度代码: controllers.controller('UniSearch',function(SearchUniversity){ var self = this; self.query = query; self.
null
。selectItem(item)中的项和范围中的值都不会更改
角度代码:
controllers.controller('UniSearch',function(SearchUniversity){
var self = this;
self.query = query;
self.selectItem = selectItem;
function query (searchText) {
unis = SearchUniversity.get({ query : self.queryText });
return unis.$promise.then(function(data) {
var thing = [];
// Just some code to reformat the data coming from the server
angular.forEach(data,function(value,key){
if (angular.isUndefined(value.UNI_ID)){
return
}
thing.push(value);
});
console.log(thing)
return thing;
});
}
function selectItem(item) {
console.log(item);
}
});
HTML:
<div ng-controller="UniSearch as ctrl">
<md-autocomplete
md-selected-item="ctrl.selected"
md-search-text="ctrl.queryText"
md-items="uni in ctrl.query(queryText)"
md-item-text="ctrl.selected.uni_international_name"
md-autoselect="true"
placeholder="Search for you city"
md-selected-item-change="ctrl.selectItem(item)">
<md-item-template>
<span md-highlight-text="queryText" md-highlight-flags="^i">
{{uni.uni_international_name}}
</span>
</md-item-template>
<md-not-found>
No universities matching "{{ctrl.queryText}}" were found.
</md-not-found>
</md-autocomplete>
</div>
{{uni.uni_international_name}
未找到与“{ctrl.queryText}}”匹配的大学。
我错过了什么?如果不运行代码,thx很难调试,但似乎有点奇怪,你列举了在
md itens上调用uni
的itens,通过item
调用其他函数,特别是在md selected item
有什么办法可以把它放在提琴或密码笔上以便于帮助吗?我在提琴工作时遇到了问题。这是相对较大的代码库的一部分。只是想知道是否有什么明显的错误…这很有效。我不希望名字在这个例子中起作用。很乐意帮忙,所以请你把它标记为正确的答案好吗?我从来没有弄明白Luiz上面的确切意思,但我的答案是md选择的文本和md项目模板需要解析为同一个东西,所以我有效地使用了md项目文本=“uni.uni\u international\u name”
这对我很有效。