2012-05-08 2 views
2

나는 jQuery 스티커 메모 플러그인을 사용한다. http://www.jquery-sticky-notes.com/ 나는 asp.net 웹 서비스와 아약스를 사용하여 메모를 만들고 편집하고 삭제 한 다음 json 배열을 사용하여 데이터베이스에서 메모를 얻는다. 문제는 : 지금 하나의 참고 경우는jquery sticky notes plugin

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); 
     }); 

노트 노트 속성을 포함 옵션 배열을 사용하여 데이터베이스 에서 메모와 함께이 플러그인을 게재하지 못할 : - 은 내가 어떻게이 배열을 사용하여 데이터베이스에서 메모와 함께이 플러그인을 populete 수 있습니다

+0

유는 http://jsfiddle.net/에서 U에게 코드를 붙여 넣을 수 있고 JQuery와 AJAX 샘플 JSON 배열 또는 웹 서비스 출력. u r asp.net mvc 3 사용 하시겠습니까? – Thulasiram

+0

http://jsfiddle.net/qA8NA/1/ –

+0

var Jnotes1 = $ .parseJSON (data); var Jnotes2 = JSON.stringify (data) 여기에 Jnotes2의 출력을 붙여 넣을 수 있습니까? – Thulasiram

답변

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); 
+1

jquery 또는 ajax를 사용하여 노드를 동적으로 추가하는 것이 좋습니다. – Talha

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); 
       } 
      }); 
     }); 
+0

var Jnotes1 = $ .parseJSON (데이터); var Jnotes2 = JSON.stringify (데이터) 여기에 Jnotes2의 출력을 붙여 넣을 수 있습니까? – Thulasiram

+0

$ .parseJSON (data.d);을 사용하지 마십시오. 그것은 단일 차원 배열을위한 것입니다. – Thulasiram