我在Angular.js网站上实现了md-autocomplete。搜索和选择工作,它更新显示的列表和一切。但由于某种原因,我无法阅读所选项目。无论我如何定义我的md-selected-item,它都将始终保持 AngularCode: HTML: 我错过了什么? THX null
。 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);
}
});
<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>
答案 0 :(得分:0)
在没有运行代码的情况下很难调试,但是在uni
md-itens
item
上调用md-selected-item
以及{"data": [{"mykey": "someval"}, {"mykey": "someotherval"}], "foo": "bar"}
特别是在public MyClass {
public String mykey;
}
处调用"data"
时,似乎有点奇怪