vin*_*tot 22 javascript url jquery param angularjs
在我使用JQuery之前,我使用它来发送带参数的URL
window.location = myUrl + $.param({"paramName" : "ok","anotherParam":"hello"});
Run Code Online (Sandbox Code Playgroud)
但是对于angularjS,这不起作用
$scope.myButton = function() {
$window.location.open = myUrl + $.param({"paramName" : "ok","anotherParam":"hello"});
};//Error: $ is not defined
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮我在angularJs中做到这一点
Raf*_*jac 36
有一个角度内置的序列化器,模仿$ .param(): $ httpParamSerializerJQLike
Sud*_*oti 12
如果您尝试创建像$ .param()那样的数据的序列化表示,
function serializeData( data ) {
// If this is not an object, defer to native stringification.
if ( ! angular.isObject( data ) ) {
return( ( data == null ) ? "" : data.toString() );
}
var buffer = [];
// Serialize each key in the object.
for ( var name in data ) {
if ( ! data.hasOwnProperty( name ) ) {
continue;
}
var value = data[ name ];
buffer.push(
encodeURIComponent( name ) + "=" + encodeURIComponent( ( value == null ) ? "" : value )
);
}
// Serialize the buffer and clean it up for transportation.
var source = buffer.join( "&" ).replace( /%20/g, "+" );
return( source );
}
Run Code Online (Sandbox Code Playgroud)
并将其用于数据序列化
小智 8
AngularJs的核心有jquery lite,因此你可以使用angular.element.param()而不是$ .param()
| 归档时间: |
|
| 查看次数: |
33177 次 |
| 最近记录: |