我想实现以下功能:

假设您有1个输入字段和2个下拉列表。在输入字段中,您可以填写您的电子邮件地址,然后旁边可以选择此电子邮件的类型类型(个人,专业,其他,或者)。

现在在第三个下拉列表中,您将看到您可以选择的电子邮件列表,您喜欢的电子邮件地址。

所以应该发生什么:

1)如果输入字段中没有任何内容,则首选的电子邮件下拉列表是空的(这已经是这种情况)。

2)当填写电子邮件和类型时,首选的电子邮件下拉列表应包含此值: test@test.com(个人)

3)当有一个填写的电子邮件但无类型时,首选的电子邮件下拉列表应包含此值: test@test.com 例如,如此,因此没有类型。


HTML:

<div ng-repeat="email in contactInfo.emails">
    <input id="email" type="text" ng-model="email.email"/>
    <select id="emailType" ng-model="email.emailTypeId" ng-options="emailType.id as emailType.name for emailType in emailTypes">
        <option value="">Choose...</option>
    </select>
</div>

<br/><br/>

<label>Preferred e-mail:</label>
<select style="margin-left: 20px; width: 50%;" id="preferred-email" ng-model="contactInfo.preferredEmail" ng-options="email.email for email in (contactInfo.emails | filter:filterEmail) track by email.id">
    <option value="">Choose...</option>
</select>
.


JavaScript:

function MyCtrl($scope){
    $scope.contactInfo = {};
    $scope.emailTypes = [{"label":"Personal","id":1,"name":"Personal","rank":2},{"label":"Professional","id":2,"name":"Professional","rank":2},{"label":"Other","id":3,"name":"Other","rank":4}];

    $scope.contactInfo.emails = [{"id":1100, "emailTypeId":2,"email":"member@test.com"}, {"id":1200, "emailTypeId":1,"email":"member2@test.com"}];
    $scope.contactInfo.prefferedEmail = {};

    $scope.filterEmail = function(email){
        return (email.email);
    }
}
.


jsfiddle:

这里是小提琴,但只有第一个工作。

我没有蚂蚁线索,所以如果有人可以帮助我这会很棒。谢谢你的时间。

sven。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top