2017-09-13 26 views
0

我使用後在我的應用程序代碼:AngularJS預輸入 - 顯示也版本的複選框,文件的選擇

  <input type="text" 
        class="form-control" 
        placeholder="Search document" 
        data-ng-model="file" 
        typeahead="document as document.fileName for document in vm.findDocumentsByTerm($viewValue)" 
        typeahead-min-length="2" 
        typeahead-wait-ms="100" 
        typeahead-editable="false" 
        typeahead-on-select="vm.attachFile(file)" /> 

,我不僅會顯示文件名(document.fileName),但文件也版本(document.versions),它是一個數組和一個複選框,以便選擇文檔的一個版本。 有沒有可能做到這一點?

[編輯] 感謝yeslcan,這正是我所需要的。目前,它看起來像這樣:

dropdown

,這是我的html代碼:

<input type="text" 
    class="form-control" 
    data-ng-model="file" 
    typeahead="document as document.fileName for document in vm.findDocumentsByTerm($viewValue)" 
    typeahead-template-url = "sampleTemplate.htm" /> 
<script type="text/ng-template" id="sampleTemplate.htm"> 
    <div> 
    <table class="table"> 
     <tr data-ng-click="$event.stopPropagation()"> 
      <td>{{match.model.fileName}}</b></td>   
      <td> 
       <div data-ng-repeat="documentFileVersion in match.model.documentFileVersions"> 
        <input type="checkbox" data-ng-model="vm.documentFileVersion" data-ng-click="vm.addDocumentFile(vm.documentFileVersion)" /> {{documentFileVersion.version}} 
       </div> 
      </td> 
     </tr> 
    </table> 
    </div> 
</script> 

目前功能vm.addDocumentFile(vm.documentFileVersion)不會被調用。有沒有人知道我必須做什麼才能調用這個函數?

+0

我不明白你的問題,請澄清 –

+0

與發佈代碼僅在文檔的文件名顯示在下拉菜單中,我的問題是,如果有可能顯示文件名和相應版本(vers離子是一個文件的浪花) – quma

+0

你的意思是每個文件應該有一個選項可用於該文件的每個版本? – user125661

回答

1

我相信我完全理解你的問題,我想你可以創建一個模板(e.eg. sampleTemplate.html),像這樣的內容(更改格式,您認爲合適)

<div> 
     <span ng-bind-html="match.model.fileName + match.model.version | uibTypeaheadHighlight:query"></span> 
    </div> 

然後 使用模板

class="form-control" 
       placeholder="Search document" 
       data-ng-model="file" 
       typeahead="document as document.fileName for document in vm.findDocumentsByTerm($viewValue)" 
       typeahead-min-length="2" 
       typeahead-wait-ms="100" 
       typeahead-editable="false" 
       typeahead-on-select="vm.attachFile(file)" 
       typeahead-template-url = "sampleTemplate.htm" /> 
+0

非常感謝,它正是我需要的設計!你知道我的功能可以在服務中調用 - data-ng-click =「vm.addDocumentFile(vm.documentFileVersion)」不會在我的AngularJS服務中調用該函數。謝謝!! – quma

+0

很高興我能幫到你。請標記爲答案。 – yesIcan

+0

你知道我的功能可以在服務中調用嗎? – quma

相關問題