1

以下のようなjsonオブジェクトがあります

keyword = {
    application: ["Athena","EWindow","EWS","FACT","FTP","Hardware","PEN","Hermes","Infrastructure","LNG Tracker","M2M","Maintenance","Microsite","Oracle","Platts.com","PMC","PTO Task","Sametime","Third Party Data","User Error","Vendor","Web Channels","XML-DD","Customer Request","Mark Logic","SBB","Market Engagement Form","Lotus Notes Database","Oracle11i","External News","Stringers","PRP","Kingsman","Hermes-1"],
    incidentType: ["Publishing Failure","Brand Damage","Security Failure","Content Creation Failure","Internal failure","External Failure","System Failure","Operational Failure","Editorial Failure","Content inaccuracy","Process Failure","Application Issue","Infrastructure Issue","User Issue","Other","Resend","Data Send validation","Customer issue"],
    incidentEnvironment: ["Production","Non-Production","Others"],
    incidentPriority: ["Low","Medium","High","Critical"],
    incidentLocation: ["Asia Pacific","Europe","New York","New Jersey","Houston","Washington DC","Others"],
    incidentStatus: ["Initiation","Work In Progress","Completed","On Hold","Closed","Cancelled"],
    incidentCategory: ["ActiveX","Checkin","Checkout","CKEditor","Corrupt Story","Delete Story","Delivering Content","Download-Upload","Filter","Graph-Rich Media","IE Cache","IE Setting","Indicia","InDesign","Infrastructure","Ingest(Table)","Other","PDF","Publish","Search","Table","User Issue"],
    incidentTicketTools: ["BMC Remedy"],
}
<div class="col-lg-3">
    <select name="txt_inc_Status" class="form-control input-sm" required>
        <option selected disabled>
            -- Select Status --
        </option>
        <option ng-repeat="incidentStatus in keywords.incidentStatus" value="{{incidentStatus}}">
            {{incidentStatus}}
        </option>
    </select>
</div>

これらの値を選択ボックスに入力する必要があります。例:Keywords.application in application選択ボックスなど。

以前はng-repeat、オプションを作成していました。しかし、そうすることはお勧めできないことを知りました。

だから私は使用しようとしていますが、これを設定するng-optionのが困難です。誰かがこれについて私を助けることができますか?

また、これらの選択ボックスのデフォルト値 (ランダム) を選択する必要があります。どうすればそれを達成できますか。使ったらダメだったng-repeat

4

1 に答える 1

2

使用できます

<div ng-repeat="(key, value) in keywords">
    <select ng-options="item for item in value" ng-init="index = getRandomIndex(value)" ng-model="value[index]">{{item}}</select>
</div>

現在の配列のランダムインデックスを取得する関数と一緒に

$scope.getRandomIndex = function(item){
    var index = Math.floor((item.length * Math.random()));
    return index;
}

DEMO

于 2013-08-26T16:26:42.983 に答える