2013-04-02 42 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(...)'。 现在工作的一个梦想,对我有几个问题。 –