在Javascript中直接获取Lotus Notes中的视图信息/记录
Directly Getting View Information/Records in Lotus Notes in Javascript
基本上我需要从lotus notes本身的视图访问一些记录或数据。我不能使用@DBLookup
,因为我们的目标是不刷新表单。我知道使用AJAX是可能的,虽然我还没有尝试过AJAX,如果你有一个详细的教程,请在这里分享。
我的主要问题是基本上有没有其他更容易的方法来访问视图中的这些记录?在字段的javascript部分直接编码。非常感谢。
基本上@DbLookup
= "?"Javascript(非AJAX).
我将按照Torsten的建议,创建一个Lotusscript代理,它执行查找并返回带有数据的JSON对象。然后,您可以使用Javascript或(更简单)jQuery从您的网页对该代理进行ajax调用。
我在我的博客上贴了一些代码。它正在做类似的事情,但不是执行视图查找,而是根据文档ID检索特定文档的值。你可以在这里找到代码和更详细的解释:http://blog.texasswede.com/code-snippet-jquery/
这是jQuery代码:function loadNotesFields(docunid) {
var notesfieldname = "";
$.ajax({
url: "/database.nsf/ajax_GetNotesFieldFields?OpenAgent",
data: {"NotesUNID":docunid},
cache: false
}).done(function(data) {
$('input[notesfield]').each(function() {
notesfieldname = $(this).attr("notesfield");
$(this).val(data[notesfieldname]);
});
});
}
下面是Lotusscript代码:
Dim urldata List as String
Sub Initialize
Dim session As New NotesSession
Dim webform As NotesDocument
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim urlstring As String
Dim urlarr As Variant
Dim urlvaluename As Variant
Dim i As Integer
Dim json As String
Set webform = session.DocumentContext
'*** Remove leading "OpenAgent" from Query_String
urlstring = StrRight(webform.Query_String_Decoded(0),"&")
'*** Create list of arguments passed to agent
urlarr = Split(urlstring,"&")
For i = LBound(urlarr) To UBound(urlarr)
urlvaluename = Split(urlarr(i),"=")
urldata(urlvaluename(0)) = urlvaluename(1)
Next
Set thisdb = session.CurrentDatabase
'*** Create content header for return data
Print "content-type: application/json"
'*** Get Notes document baed on NotesUIND argument
Set doc = db.GetDocumentByUNID(urldata("NotesUNID"))
'*** Build JSON for all fields in document except $fields
json = "{" + Chr$(13)
ForAll item In doc.Items
If Left$(item.Name,1)<>"$" Then
json = json + |"| + item.Name + |":"| + item.Text + |",|+ Chr$(13)
End If
End ForAll
'*** Remove trailing comma and line break
json = Left$(json,Len(json)-2)
json = json + "}"
'*** Return JSON
Print json
End Sub
如果这是一个XPages问题,那么答案很简单:使用JavaScript @DBLookup。
对于"经典"web开发来说,这并不容易。您需要编写一个代理,它以您想要的任何格式返回@DBLookup的结果,并使用ajax调用调用该代理。它看起来像这样:
LotusScript- Agent,触发none
Dim ses as New NotesSession
Dim db as NotesDatabase
Dim viw as NotesView
Dim dc as NotesDocumentCollection
Dim doc as NotesDocument
Set db = ses.CurrentDatabase
Set viw = db.GetView( "YourLookupView" )
Set dc = viw.GetAllDocumentsByKey( "YourLookupKey" )
Set doc = dc.GetFirstDocument
While not doc is Nothing
Print doc.GetItemValue( "NameOfItemToReturn" )(0)
Set doc = dc.GetNextDocument( doc )
Wend
这个代理将返回一个包含所有值的"page",每个值一行。然后,在ajax- return-函数中,您可以对这些值做您想做的事情。
通常你不是简单地打印值,而是返回json- object,或者一些xml-结构,或者已经html作为有序列表,或者其他什么,但是原则应该是明确的。
然后你调用代理(例如ajax调用):hxxp://server/db.nsf/AgentName?OpenAgent
另一种可能性是使用hxxp://server/db.nsf/YourLookupView?ReadViewEntries&restricttocategory=YourCategory
或hxxp://server/db.nsf/YourLookupView?ReadViewEntries&restricttocategory=YourCategory&OutputFormat=json
这样的url,并使用"原生"javascript解析结果…
- 如何在模型获取完所有信息后才将其传递给视图's数据
- DHTMLX 移动调度程序事件详细信息视图高度问题
- 获取视图中可见数据的信息 - AngularJS
- ASP.net VB 详细信息视图插入:取消问题的 javascript 回发
- 使用 ng-href 在具有 objectId 的集合的 ng-repeat 中查看示例详细信息视图
- 带有外部 JSON 文件的离子详细信息视图
- 详细信息视图 ASP.Net 取消客户端的默认编辑模式
- 有没有办法在 MVC 中的视图上使用 ajax 调用来使用新信息刷新页面
- 获取嵌套网格视图中图像鼠标悬停的动态详细信息
- EmberJS 应用程序中列表 + 详细信息 + 编辑视图的数据处理
- MVC3 :: 从详细信息视图导航表,而不是单击表中的详细信息链接
- 在视图之间传递参数以显示信息
- 如何将谷歌地图和基于骨干视图的信息框结合起来
- Rails-将信息从视图传递到Javascript
- 烬实现列表/详细信息视图
- 使用详细信息视图,在Page_Load(或任何地方)期间是否有任何方法只显示非空字段?
- 我如何在主干视图中获得尺寸(高度/宽度)信息
- 在视图中显示passport.js认证错误信息
- 在网格视图中弹出更多详细信息
- 在Javascript中直接获取Lotus Notes中的视图信息/记录