2

我使用 jQuery Sticky Notes 插件http://www.jquery-sticky-notes.com/ 我使用 asp.net Web 服务和 ajax 将它与数据库连接以创建笔记并编辑和删除,然后我使用 json 数组从数据库中获取笔记. 问题是:我无法使用数据库中的注释填充此插件,它使用选项数组

jQuery(document).ready(function() {
            var options = {
                notes:[{"id":1,
                      "text":"Test Internet Explorer",
                      "pos_x": 50,
                      "pos_y": 50,  
                      "width": 200,                         
                      "height": 200,                                                    
                    }]
                ,resizable: true
                ,controls: true 
                ,editCallback: edited
                ,createCallback: created
                ,deleteCallback: deleted
                ,moveCallback: moved                    
                ,resizeCallback: resized                    

            };
            jQuery("#notes").stickyNotes(options);
        });

如果现在有一个注释,则注释包含注释属性:- 我如何使用这一系列选项从数据库中的注释填充此插件

4

2 回答 2

2

尝试下面的代码并根据代码中的注释填充Note数组,从第 3 行开始(您需要放置一个For循环或其他东西)。然后将数组分配给option.notes倒数第二行。

jQuery(document).ready(function() {
            var note= new Object();
            ///////Populate the Notes array here
            note=[{"id":1,
                          "text":"Sticky Text1",
                          "pos_x": 20,
                          "pos_y": 50,  
                          "width": 200,                         
                          "height": 200,                                                    
                        },{"id":1,
                          "text":"Sticky Text 2",
                          "pos_x": 50,
                          "pos_y": 50,  
                          "width": 200,                         
                          "height": 200,                                                    
                        }];
                ///////Populate the Notes array here

                var options = {
                    notes:null
                    ,resizable: true
                    ,controls: true 
                    ,editCallback: edited
                    ,createCallback: created
                    ,deleteCallback: deleted
                    ,moveCallback: moved                    
                    ,resizeCallback: resized                    

                };
                options.notes=note;
                jQuery("#notes").stickyNotes(options);
于 2012-05-08T12:54:34.600 回答
0
 $(documet).ready(function () {
            //calling for edit text      
            var edited = function (note) {
                alert("Edited note with id " + note.id + ", new text is: " + note.text);
            };
            // calling:create new note to add it to database
            var created = function (note) {
                alert("Created note with id " + note.id + ", text is: " + note.text);
            };

            //calling to delete note from database
            var deleted = function (note) {
                alert("Deleted note with id " + note.id + ", text is: " + note.text);
            };

            //calling to update location
            var moved = function (note) {
                alert("Moved note with id " + note.id + ", text is: " + note.text);
            };

            //calling to update size
            var resized = function (note) {
                alert("Resized note with id " + note.id + ", text is: " + note.text);
            };

            $.ajax({
                type: "POST",
                url: "../../Services/sticky_notes.asmx/getnotes",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function suc(data, status) {
                    var Jnotes = $.parseJSON(data);

                    //i have json now how can i use it to populate option
                    var options = {
                        notes: Jnotes,
                        resizable: true,
                        controls: true,
                        editCallback: edited,
                        createCallback: created,
                        deleteCallback: deleted,
                        moveCallback: moved,
                        resizeCallback: resized
                    };

                    $("#notes").stickyNotes(options);
                },
                error: function error(request, status, error) {
                    csscody.alert(request.statusText);
                }
            });
        });
于 2012-05-08T13:28:04.880 回答