2013-04-02 45 views
1

ScriptSharp的生產JavaScript不能找到我的類方法「LoadContent()」。我在哪裏錯了?ScriptSharp類方法沒有找到

這似乎是把方法爲原型,但我不知道這是什麼,我需要。任何幫助將不勝感激。

namespace Echo.Web.JScript 
{ 
    [ScriptNamespace("Scripts")] 
    public class MasterTrackerActions 
    { 
     private jQueryObject _source; 

     public MasterTrackerActions(string fundCodeSourceId) 
     { 
      _source = jQuery.Select("#" + fundCodeSourceId); 
      _source.Change(delegate 
       { 
        Script.Alert("Here we go"); //We see this fine. 
        LoadContent(); 
       }); 
     } 

     public void LoadContent() 
     { 
      Script.Alert("Do we get here?"); //Answer is no 
     } 
    } 
} 
+0

好像你正在使用的版本0.7倍。你能發佈你生成的JavaScript嗎? – theoutlander

回答

2

我在0.8版本中試過,它按預期工作(通過AMD模式)。我對代碼做了輕微的修改,使其在0.8版本中編譯。

  • 更改Script.Alert到Window.Alert
  • 移除ScriptNamespace並加入[組件:ScriptAssembly( 「腳本」)]中的AssemblyInfo.cs

在S#類

using System.Html; 
using jQueryApi; 

namespace Echo.Web.JScript { 
    public class MasterTrackerActions { 
     private jQueryObject _source; 

     public MasterTrackerActions(string fundCodeSourceId) { 
      _source = jQuery.Select("#" + fundCodeSourceId); 
      _source.Change(delegate { 
       Window.Alert("Here we go"); //We see this fine. 
       LoadContent(); 
      }); 
     } 

     public void LoadContent() { 
      Window.Alert("Do we get here?"); //Answer is no 
     } 
    } 
} 

生成的JS文件是

/*! Scripts.js 1.0.0.0 
* 
*/ 

"use strict"; 

define('Scripts', ['ss', 'jquery'], function(ss, $) { 
    var $global = this; 

    // Echo.Web.JScript.MasterTrackerActions 

    function MasterTrackerActions(fundCodeSourceId) { 
    var $this = this; 

    this._source = $('#' + fundCodeSourceId); 
    this._source.change(function() { 
      alert('Here we go'); 
      $this.loadContent(); 
     }); 
    } 

    var MasterTrackerActions$ = { 
     loadContent: function() { 
      alert('Do we get here?'); 
     } 
    }; 

    var $exports = ss.module('Scripts', null, 
    { 
     MasterTrackerActions: [ MasterTrackerActions, MasterTrackerActions$, null ] 
    }); 

    return $exports; 
}); 

現在要在HTML文件中使用它,您需要使用提供的ModuleLoader SSLoader.js或RequireJS(首選)。在這種情況下,您需要帶JQuery的RequireJS模塊。有不同的方法可以包含JQuery(這裏超出了範圍)。

HTML文件

<!DOCTYPE html> 

<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <meta charset="utf-8" /> 
     <title></title> 
    </head> 

    <body> 
     <script type="text/javascript" data-main="Scripts/MyScript.js" src="Scripts/require-jquery.js"></script> 

     <script type="text/javascript"> 
      require(['MyScript'], function (ms) { 
       var tracker = new ms.MasterTrackerActions('sampleText'); 
       console.log(tracker); 
      }); 
     </script> 

     <textarea id="sampleText">TEST123</textarea> 
    </body> 
</html> 

哦,還有一兩件事,當控件失去焦點事件觸發...

+0

輝煌。你無意中指出了我的方式的錯誤。我簡單地調用 'Scripts.MasterTrackerActions(...)' 而不是 '變種x =新Scripts.MasterTrackerActions(...)'。 現在工作的一個夢想,對我有幾個問題。 –