md-autocomplete在ng-repeat中生成相同的模型

时间:2017-08-07 08:51:08

标签: angularjs md-autocomplete

md-autocomplete在ng-repeat中生成相同的模型 如果一个变化的值也反映在其他领域, 如何为其添加不同的ng模型?

LdapQuery query = LdapQueryBuilder.query()
            .base("ou=dev")
            .where("objectClass").is("group");

    return ldapTemplate.search(query, new AttributesMapper<String>() {
        @Override
        public String mapFromAttributes(Attributes attributes) throws NamingException {
            return (String) attributes.get("cn").get();
        }
    });

生成的模型为所有行提供类似的内容:

<tr ng-repeat="school in ctrl.schools" ng-if="ctrl.editAcademyToggle">
<td>
<md-input-container>
<div class="mdInputContainer">
    <md-autocomplete flex required flex-gt-sm="25"
        md-autofocus="true"
        md-selected-item="school.college_name"
        md-clear-button="false"
        md-input-name="school.college"
        md-input-minlength="3"
        md-no-cache="false"
        md-search-text="ctrl.academySearchStr"
        md-items="item in ctrl.searchAcademySchools(ctrl.academySearchStr)"     
        md-item-text="item.name">
        <md-item-template>
            <span class="item-title">
                <span> {{item.name}}, {{item.city}}, {{item.state}}, {{item.zip}}</span>
            </span>
        </md-item-template>
        <md-not-found>
            <span ng-if="ctrl.academySearchStr.length < 3">Minimum 3 Charaters</span>
            <span ng-if="ctrl.academySearchStr.length >= 3">
              Wait a few more seconds before searching again"
            </span>
        </md-not-found>
        <div ng-messages="ctrl.leadEntryForm.school.college.$error">
            <div ng-message="required">This field is required</div>
        </div>
    </md-autocomplete>
</div>
</md-input-container>
</td>
</tr>

1 个答案:

答案 0 :(得分:1)

schools视为数组。

你可以映射它为搜索文本添加变量,而不是在任何地方使用相同的搜索文本,比如

schools.map(function(obj){
    obj.searchText = null;
});

并在此处传递此搜索文字

md-search-text="school.searchText"