我在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.7倍。你能发布你生成的JavaScript吗? – theoutlander