0

我的代码在jsFiddle中,下面是该代码的 c/p。我的问题是当我单击星期一选项时如何获取文本Mon而不是["Mon"] ,以及当我多选星期一和星期四时如何获取Mon、Thu (ofc,你明白了: Tue ,周三,周二,星期三和周六选择时,星期六)。我一定遗漏了一些明显的东西,所以请引导我朝着正确的方向前进。

html:

 <div ng-app ng-controller="Controller">
    <select multiple="multiple" ng-model="day" ng-options='day.id as day.name for day in days'></select>

    {{day}}
</div>

js:

function Controller($scope) {
    $scope.days = [
        {
            name: "Monday",
            id: "Mon"
        },
        {
            name: "Tuesday",
            id: "Tue"
        },
        {
            name: "Wednesday",
            id: "Wed"
        },
        {
            name: "Thursday",
            id: "Thu"
        },
        {
            name: "Friday",
            id: "Fri"
        },
        {
            name: "Saturday",
            id: "Sat"
        },
        {
            name: "Sunday",
            id: "Sun"
        }
    ];    
}
4

1 回答 1

1

这是一个将数组转换为字符串并直接在页面中显示为字符串的示例:

JS:

$scope.selectedDaysToString = function() {
    return $scope.day.join(', ');
}

HTML:

{{selectedDaysToString()}}

这是一个生成包含所有选定日期的列表的示例:

HTML:

<ul>
    <li ng-repeat="d in day">{{d}}</li>
</ul>
于 2013-07-07T12:03:16.630 回答