-3
請問如何將下面提到的角下拉框表達式轉換爲對象數組? B'cos我必須使用對象數組,而不是使用下面提到的下拉指令的角度表達式。提前感謝。將角(javascript)表達式轉換爲對象數組
a.id as a.num + ', '+ a.townName for a in vm.schoolDistricts
這是指令:Typeahead Dropdown
請問如何將下面提到的角下拉框表達式轉換爲對象數組? B'cos我必須使用對象數組,而不是使用下面提到的下拉指令的角度表達式。提前感謝。將角(javascript)表達式轉換爲對象數組
a.id as a.num + ', '+ a.townName for a in vm.schoolDistricts
這是指令:Typeahead Dropdown
由於@Grundy我在評論中指出,該指令只能採取任何屬性,從你的陣列。因此,爲了克服這一點,你可以包括表達你想
a.num + ', '+ a.townName
。
如果您當前的陣列看起來像,
schoolDistrict = [{name:"ABC", value: "ABCVal", num: "123", townName: "myTown"}, ....]
那麼需要改變的東西一樣,
schoolDistrict = [{name:"ABC", value: "ABCVal", num: "123", townName: "myTown", typeAheadLabel:"123, myTown"}, ....]
有了這個,你將能夠在配置使用typeAheadLabel一樣,
$scope.config = {
modelLabel:'districts',
optionLabel:'typeAheadLabel'
};
在視圖中,您可以使用類似的東西,
<typeahead-dropdownng-model="vm.property.schoolDistrictId" class="form-control"
options="vm.schoolDistricts" config="config" required>
<option value="" disabled="">-- Select a School District --</option> </typeahead-dropdown>
非常感謝。我會試試這個,讓你知道:) – Sampath
在角度表達式中,您還可以指定一個可以調用以檢索值的方法。請嘗試如果工作 – M22an
@ M22an這裏的問題是上述指令不接受角度表達式。這就是爲什麼我需要將上面的表達式轉換爲上面的指令可以使用它的對象數組。這裏是指令:https:// github.com/spongessuck/gm.typeaheadDropdown – Sampath
從文檔看來,您需要在集合'schoolDistricts'中添加另一個字段,例如'typeAheadContent',並在配置的'optionlabel'中提供該字段。 – M22an