在此之前,我问一个问题,如何在here中通过Web浏览器显示通讯簿。然后,我找到了一个可以运行并在通讯簿中找到所有信息的代理。但是我现在的问题是,我不知道如何显示对话框列表,以便用户可以选择任何信息。
我的特工如下:
books = s.AddressBooks
foundflag = False
ForAll b In books
If b.FileName="names.nsf" Then
Call b.Open( "", "" )
Set view = b.GetView( "People" )
Call view.Refresh
foundflag = True
Exit ForAll
End If
End ForAll
If Not foundflag Then
returnVal = "NSF file not found."
GoTo endp
End If
count = 0
Set tmpdoc = view.GetFirstDocument
Do While Not tmpdoc Is Nothing
If tmpdoc.MailFile(0) <> "" _
And tmpdoc.MailAddress(0) = "" _
And tmpdoc.InternetAddress(0)<>"" Then
count = count + 1
tmpstr = tmpdoc.LastName(0)
If tmpstr="" Then tmpstr = tmpdoc.FirstName(0)
tmplist(count) = tmpstr & "|@|" & tmpdoc.InternetAddress(0)
End If
Set tmpdoc = view.GetNextDocument(tmpdoc)
Loop
If count=0 Then
returnVal = "No employee were found"
GoTo endp
End If
我有可以调用此代理的jQuery,但我不知道如何以HTML显示列表。我的jQuery如下:
$.post("http://server/pcspec.nsf/jsonEmpList?OpenAgent",
function(data, status) {
var arr = JSON.parse(data);
if (arr.status == "success") {
$(arr.items).each(function(i, item) {
$("#PUserID").append('<option value="' + item.mail + '">' + item.name + ' (' + item.mail + ')</option>');
});
} else {
alert(arr.message);
}
})
.fail(function(xhr, status, error) {
console.log("ERROR - " + xhr + " - " + status + " - " + error);
})
所以我的问题是,如何在Web浏览器中提示对话框列表,以便用户进行选择。任何帮助将不胜感激。谢谢!
答案 0 :(得分:1)
如果您询问“如何将信息从代理返回到jQuery”,答案是PRINT语句。您在使用地址簿时出现错误,因此我对公共地址簿的名称进行了硬编码。但是,此代码段将返回JSON对象。当然,您需要声明适当的变量并相应地设置服务器名称。
Set db = s.getDatabase("server/document","names.nsf",False)
If db Is nothing Then
print "ERROR: Names.nsf not found</br>"
exit sub
End If
Set view=db.getView("People")
Set tmpdoc = view.GetFirstDocument
Do While Not tmpdoc Is Nothing
If tmpdoc.MailFile(0) <> "" _
And tmpdoc.MailAddress(0) = "" _
And tmpdoc.InternetAddress(0)<>"" Then
tmpStr = ToJSON(tmpdoc)
Print tmpStr + "<br />"
End If
Set tmpdoc = view.GetNextDocument(tmpdoc)
Loop
结果:
{"value": "CN=John Doe/O=ACME", "text": "john.doe@acme.com"}
{"value": "CN=Jane Smith/O=ACME", "text": "jane.smith@acme.com"}
答案 1 :(得分:0)
我今晚早些时候正在做类似的事情。但是我的方法有些不同。就我而言,我在下拉字段中使用插件Select2,用户可以从列表中选择一个人。
// Initialize Select2 dropdown
$('[data-dropdown="names"]').select2({
allowClear: true,
theme: 'bootstrap',
width: '100%',
minimumResultsForSearch: 20,
minimumInputLength: 3,
delay: 450,
ajax: {
url: "/agents/getContactList.json?OpenAgent",
dataType: "json",
data: function(params) {
var query = {
term: params.term
};
return query;
}
}
});
<div class="form-group">
<label for="selectContact">Contact Name</label>
<select id="selectContact" class="form-control input-sm dominoDropdown" data-placeholder="">
<option value=""></option>
</select>
</div>
通过对Lotusscript代理的Ajax调用填充Select2下拉列表,该代理返回所有与该下拉列表中输入的内容部分匹配的名称。您当然也可以预先加载所有数据,但是根据NAB中文档的数量,它可能很慢。
下面是Lotusscript代理的代码。它使用我自己的类进行URL查询字符串解析和JSON生成,但是在Domino 10中,您内置了类。我通过删除一些正在使用的额外选项来简化了代码。
Option Public
Option Declare
Use "Class.JSON"
Use "Class.URL"
Sub Initialize
'--- Local Notes classes used in agent
Dim session As New NotesSession
Dim db As NotesDatabase
Dim col As NotesViewEntryCollection
Dim view As NotesView
Dim columns As Variant
Dim column As NotesViewColumn
Dim entry As NotesViewEntry
'--- Custom classes
Dim json As JSONData
Dim url As New URLData()
'--- Local variables
Dim jsontxt As String
Dim i As Integer
Dim value As String
Dim filtervalue As String
Dim id As String
Dim options As String
Dim lookupview As String
Dim query As String
'*** Get document
Set db = session.CurrentDatabase
lookupview = "(lookup_Contacts)"
Set view = db.GetView(lookupview)
If view Is Nothing Then
MsgBox "Contact view not found"
Exit Sub
End If
Call view.Refresh()
jsontxt = "[ "
'*** Get all entries in view
Set col = view.AllEntries()
'*** Reduce the collection using a full-text search
query = |[LastName] CONTAINS *| & url.GetValue("term") & |* OR [FirstName] CONTAINS *| & url.GetValue("term") & |*|
Call col.FTSearch(query,0)
If col Is Nothing Then
MsgBox "col is nothing!"
Exit Sub
End If
'*** Loop through view entries and build the JSON to return
Set entry = col.GetFirstEntry()
Do Until entry Is Nothing
value = CStr(entry.ColumnValues(3)) ' Name to display
If InStr(LCase(value),LCase(filtervalue))>0 Then
id = CStr(entry.ColumnValues(2)) ' UNID
Set json = New JSONdata()
Call json.NoStatus()
Call json.SetValue("id", id)
Call json.SetValue("text", value)
jsontxt = jsontxt + json.GetJSON() + ","
End If
Set entry = col.GetNextEntry(entry)
Loop
'*** Remove trailing comma
If Len(jsontxt)>4 Then
jsontxt = Left$(jsontxt, Len(jsontxt)-1)
End If
jsontxt = jsontxt + " ]"
'*** MIME Header to tell browser what kind of data we will return (Javascript).
'*** See http://www.rfc-editor.org/rfc/rfc4329.txt
Print "content-type: application/javascript; charset=utf-8"
Print |{ "results": |+jsontxt+| }|
End Sub
祝你好运!