ScriptSharp生成的Javascript无法找到我的类方法“LoadContent()”。我哪里错了?
似乎将该方法放入原型,但我不确定这是我需要的。任何帮助将不胜感激。
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 :(得分:2)
我在0.8中尝试了这个,它按预期工作(通过AMD模式)。我对你的代码稍作修改,使其在0.8中编译。
S#class
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>
哦,还有一件事,当控件失去焦点时会触发事件......