2016-12-06 38 views
0

我有一個表格,它動態顯示輸入字段,這意味着對於特定的客戶顯示不同的輸入字段。序列和顯示哪些輸入字段由數據庫驅動。對於每個輸入字段,我希望進行打字。完整形式表示與下面的對象:Bootstrap Typeahead複雜對象列表

{ 
    attributes:Array[9] 
    s_Id:1376 
    name:"test_name" 
    c_Id:512 
    active:true 
    created:"2016-11-28T09:47:35.000+0000" 
    updated:"2016-12-05T14:52:17.649+0000" 
    valid:Moment 
} 

有關輸入文件的所有信息被存儲在陣列的屬性,其是如下所示對象的列表。在這個對象中有數組attvalue,它顯示爲此特定字段插入的所有以前的值,並且這實際上是針對特定輸入字段的預先輸入。

{ 
    attributeId:138 
    attributevalueId:618 
    c_Id:512 
    s_Id:1376 
    attvalue:Array[4] 
     0:"Typeahead value 1" 
     1:"Typeahead value 2" 
     2:"Typeahead value 3" 
     3:"Typeahead value 4" 
    language:"en" 
    updatedAt:"2016-12-05T14:52:17.649+0000" 
    created:"2016-11-28T09:47:35.000+0000" 
} 

在視圖上我遍歷屬性數組以顯示錶單。對於顯示預輸入我在輸入HTML元素:

typeahead="attvalue as object.attvalue for object in object attributes| limitTo:100" ng-maxlength="45" autocomplete="off" 

這並不表明適當的值,這對於特定的預輸入應該這個樣子(寫在JS的方式):

object.attributes:Array[10].attvalue=["Typeahead value 1", "Typeahead value 2", "Typeahead value 3", "Typeahead value 4"] 

如何解決這個問題?更好的解決方案是解決它的觀點,然後chaning完整的控制器。

+0

我見過幾個例子在這裏SOF,但這些都是更容易一些。 – wanttobeprofessional

回答

0

我已經找到了如何解決這個問題。首先,可以製作非常複雜的列表和對象等,並且仍然使用引導程序,因爲我已經看到了很多簡單的示例。 Firt我已經添加了數組attvalues來列出attributevalueList,屬性attvalue僅用於ng-model指令的最終值。在列表中選擇新建的對象是這樣的:

object.attributes:Array[1].attvalues: 

{ 
    attributeId:138 
    attributevalueId:618 
    c_Id:512 
    s_Id:1376 
    attvalue:"" 
    attvalues:Array[4] 
     0:"Typeahead value 1" 
     1:"Typeahead value 2" 
     2:"Typeahead value 3" 
     3:"Typeahead value 4" 
    language:"en" 
    updatedAt:"2016-12-05T14:52:17.649+0000" 
    created:"2016-11-28T09:47:35.000+0000" 
} 

我已經糾正typeahed的觀點如下:

typeahead="attvalues for attvalues in object.attributevalueList[$index].attvalues | limitTo:100" ng-maxlength="45" autocomplete="off">