2

大家好,

我正在制作一个提供节点图的网页,每个节点上都应该有一个媒体(照片、视频、声音、文本)。我使用 javascript 库GoJs制作节点图,但在如何将每个节点与上传的媒体绑定时遇到问题(媒体由用户使用 Ajax 表单上传)。

有谁知道如何使这项工作?

顺便说一下媒体上传器工作正常。

到目前为止,这是我的节点图的 js 代码:

 // define the Node template for nodes
myDiagram.nodeTemplate =
  $(go.Node, "Auto",  // the whole node panel
      new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),{
      // define the node's outer shape, which will surround the TextBlock
              resizable: true, 
              resizeObjectName: "RRectangle", 
              resizeCellSize: new go.Size(10, 10),
              selectionObjectName: "SHAPE" 
              },
          
        
        $(go.Picture, {                                             //main image for all nodes
             source: "images/nodeicon.png", 
             background: "#E67E22",
             width: 65,
             height: 65,
             maxSize: new go.Size(50, 50),
             margin: new go.Margin(0), 
             },
            new go.Binding("source")),
                         
    
            )
    );


// This converter is used by the mediaUploader
    function mediaContent(mediaC) {
        use some SetDataProperty(data,source,mediaC)
      ..
    }; 

mediaContent 函数返回 php 回显。

例如'/media/IMG_4310.jpg'

媒体上传方式:Ajax表单

//------                                //
//          MEDIA UPLOAD                //
//------                                //
jQuery(document).ready(function() { 
    var options = { 
            beforeSubmit:  beforeSubmit,  // pre-submit callback 
            success:       afterSuccess,  // post-submit callback 
            uploadProgress: OnProgress, //upload progress callback 
            resetForm: true        // reset the form after successful submit 
        }; 
...

以及 php 媒体上传器的某些部分:

if(move_uploaded_file($tmp_file, $UploadDirectory.$NewFileName ))
   {
    if($File_Ext=='.jpg' || $File_Ext=='.jpg' || $File_Ext=='.png' || $File_Ext=='.gif' )
    {
        //echo "<img src='media/".$NewFileName."' id='preview' class='img-responsive'>";
        echo 'media/'.$NewFileName.'';
    }

}
else{
    die('error uploading File!');
}
4

0 回答 0