带关联数组的dwr addoptions

时间:2015-04-29 12:21:13

标签: javascript dwr

我有一个关联数组。我希望能够使用关联数组键作为选项的值和数组键作为选项元素的文本将选项添加到下拉列表。

Sub newdata()



Set appxl = CreateObject("Excel.application")
Dim myfile As Window
Dim currentSheet As Worksheet
Dim lastRow As Double
Dim sourceFileName As String


'Open Source File.xlsx
With appxl

    vFile = Application.GetOpenFilename(Title:="Select File To Be Opened")
    If vFile = False Then Exit Sub  'if the user didn't select a file, exit sub
   ' Set myfile = Workbooks.Open(vFile)


    .Visible = False
End With

'Get first sheet data
Set myfile = appxl.Windows(vFile)
myfile.Activate
Set currentSheet = myfile.Sheets(1)

'Past the table in my current Excel file
lastRow = currentSheet.Range("A1").End(xlDown).Row
Sheets("Data retrieval").Range("A1:E" & lastRow) = currentSheet.Range("A1:Q" & lastRow).Value

'Close Source File.xlsx
appxl.Workbooks(vFile).Close


End Sub

执行上述操作会创建带有文本和值的选项元素:

 var associativeArray = new Array();
 associativeArray['city'] = "Portland";
 associativeArray['state'] = "Oregon";
 associativeArray['country'] = "United States";
 dwr.util.addOptions(makeId3.id,associativeArray);

但是我期待以下内容:

<option value="city,Portland">city,Portland</option>

如何通过dwr和关联数组实现上述目标。有人建议吗?

1 个答案:

答案 0 :(得分:1)

使用对象而不是数组:

var associativeArray = {
    city: "Portland",
    state: "Oregon",
    country: "United States"
};
dwr.util.addOptions(makeId3.id, associativeArray, false);

或者,如果要动态添加属性,请使用:

var associativeArray = {};
associativeArray['city'] = "Portland";
associativeArray['state'] = "Oregon";
associativeArray['country'] = "United States";

请参阅documentation。它以不同于对象的方式处理数组参数。