在用Ajax asp.net Extension 2.0 beta 的时候遇到一个问题,在加载以前的javascript的时候出错,Sys.ScriptLoadFailedException.................. 在这里找到了答案
这个错误主要是因为在beta2 中,通过ScriptManage加入script 的时候采用了异步的方式,所以在javascript文件的最后要加多一句
if
(Sys
&&
Sys.Application) {
Sys.Application.notifyScriptLoaded();
}
Sys.Application.notifyScriptLoaded();
}
否则你就会有一个Sys.ScriptLoadFailedException。
PS:最近真的被这个版本搞s了,错了都不知道怎么错了,官方那里就那么一点文档,郁闷s。。。。。。
还有一个改进。就是对丰富了collections类型,详细请看这里吧
例子:
注意:[{name: 'customer', type: Samples.Customer, mayBeNull: false, isOptional: false}]); 是对Collection的数据类型的验证,也就是改进的地方。
Type.registerNamespace(
'
Samples
'
);
Samples.Customer = function () {
this ._fullName;
}
Samples.Customer.prototype = {
set_fullName : function (value) {
this ._fullName = value;
},
get_fullName : function () {
return this ._fullName;
}
}
Samples.Customer.registerClass( ' Samples.Customer ' );
Samples.Customer = function () {
this ._fullName;
}
Samples.Customer.prototype = {
set_fullName : function (value) {
this ._fullName = value;
},
get_fullName : function () {
return this ._fullName;
}
}
Samples.Customer.registerClass( ' Samples.Customer ' );
Samples.CustomerCollection = function() { |
this._innerList = []; |
} |
Samples.CustomerCollection.prototype = { |
addCustomer : function(customer) { |
this._validateCustomer(arguments); |
Array.add(this._innerList, customer); |
}, |
removeCustomer : function(customer) { |
this._validateCustomer(arguments); |
Array.remove(this._innerList, customer); |
}, |
get_count : function() { |
return this._innerList.length; |
}, |
_validateCustomer : function(args) { |
var e = Function._validateParams(args, |
[{name: 'customer', type: Samples.Customer, mayBeNull: false, isOptional: false}]); |
if(e) throw e; |
} |
} |
Samples.CustomerCollection.registerClass('Samples.CustomerCollection'); |
//调用
function pageLoad() { |
var c1 = new Samples.Customer(); |
c1.set_fullName('John Doe'); |
var c2 = new Samples.Customer(); |
c2.set_fullName('John Smith'); |
var coll = new Samples.CustomerCollection(); |
coll.addCustomer(c1); |
coll.addCustomer("blah"); // This will throw. |
coll.removeCustomer(c1); |
alert(coll.get_count()); |
} |