如何使用store plugin annotatorjs加载注释?

时间:2015-11-16 12:00:59

标签: javascript jquery json annotations

我正在使用Annotatorjs库,我想使用store插件中的loadFromSearch选项显示以前存储的注释。

我的返回JSON看起来像这样,

{"total":2,"rows":[{"id":"d41d8cd98f00b20","uri":"http://localhost/highlight/index.php","tags":[],"text"
:"","ranges":{"start":"/p[1]","startOffset":17,"end":"/p[1]","endOffset":21},"quote":"pork"},{"id":"9800998ecf8427"
,"uri":"http://localhost/highlight/index.php","tags":[],"text":"","ranges":{"start":"/p[1]","startOffset"
:31,"end":"/p[1]","endOffset":37},"quote":"salami"}]}

这是我的js代码

jQuery(function ($) {
//initialize annotator
var content = $('#highlightContainer').annotator();

//load tag plugin
content.annotator('addPlugin', 'Tags');
//load filter plugin
content.annotator('addPlugin', 'Filter');
/**
*load unsupoarted plugins
*This plugin provides a notification to users of these unsupported browsers letting them know that the plugin has not loaded
*/
content.annotator('addPlugin', 'Unsupported');

//load store plugin for save and retrieve annotations
content.annotator('addPlugin', 'Store', {
    // The endpoint of the store on your server.
    prefix: 'http://localhost/backend/api/web/v1/highlights',

    // Attach the uri of the current page to all annotations to allow search.
    annotationData: {
        'uri': 'http://localhost/highlight/index.php'
    },

    // This will perform a "search" action when the plugin loads. Will
    // request the last 20 annotations for the current url.
    // eg. /store/endpoint/search?limit=20&uri=http://this/document/only
    loadFromSearch: {
        'limit': 100,
        'all_fields': 1,
        'uri': 'http://localhost/highlight/index.php'
    },

    showViewPermissionsCheckbox: false,

    showEditPermissionsCheckbox: false
});
});

但我以前保存的注释没有在页面加载时突出显示。我错过了返回JSON的任何属性吗?

1 个答案:

答案 0 :(得分:0)

我有同样的问题,我能够使用商店插件中的loadFromSearch纠正这个问题。确保你的jQuery调用以下内容:

 loadFromSearch: {
'limit': 0,
'all_fields': 1,
'uri': 'http://this/dl/'

}