本文整理匯總了TypeScript中src/UrlSearchParams.get函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript get函數的具體用法?TypeScript get怎麽用?TypeScript get使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了get函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: checkParams
construct: (function () {
function checkParams(params: UrlSearchParams) {
assert.deepEqual(params.getAll('foo'), [ 'bar', 'baz' ]);
assert.deepEqual(params.getAll('bar'), [ 'foo' ]);
assert.deepEqual(params.getAll('baz'), [ '' ]);
}
return {
empty() {
// Empty UrlSearchParams should have no properties
const params = new UrlSearchParams();
assert.isNull(params.get('foo'));
},
// Next three tests should generate 'params' objects with same contents
object() {
const params = new UrlSearchParams({ foo: [ 'bar', 'baz' ], bar: 'foo', baz: null });
checkParams(params);
},
string() {
let params = new UrlSearchParams('foo=bar&foo=baz&bar=foo&baz');
checkParams(params);
// Assignments after the first will be ignored
params = new UrlSearchParams('foo=bar=baz');
assert.deepEqual(params.getAll('foo'), [ 'bar' ]);
// Handle empty keys
params = new UrlSearchParams('=foo&');
assert.deepEqual(params.getAll(''), [ 'foo', '' ]);
},
UrlSearchParams() {
const params1 = new UrlSearchParams({ foo: [ 'bar', 'baz' ], bar: 'foo', baz: null });
const params = new UrlSearchParams(params1);
checkParams(params);
}
}
})(),
示例2: UrlSearchParams
const params = new UrlSearchParams();
params.append('foo', 'bar');
assert.deepEqual(params.getAll('foo'), [ 'bar' ]);
},
'existing key'() {
const params = new UrlSearchParams({ foo: 'bar' });
params.append('foo', 'baz');
assert.deepEqual(params.getAll('foo'), [ 'bar', 'baz' ]);
}
},
'#delete'() {
const params = new UrlSearchParams({ foo: 'bar' });
params.delete('foo');
assert.isNull(params.get('foo'));
},
'#get'() {
// Get should always return the first entry for a key
const params1 = new UrlSearchParams({ foo: [ 'bar', 'baz' ] });
const params2 = new UrlSearchParams({ foo: [ 'baz', 'bar' ] });
assert.strictEqual(params1.get('foo'), 'bar');
assert.strictEqual(params2.get('foo'), 'baz');
assert.isNull(params2.get('bar'));
},
'#getAll'() {
const params = new UrlSearchParams({ foo: [ 'bar', 'baz' ] });
assert.deepEqual(params.getAll('foo'), [ 'bar', 'baz' ]);
assert.isNull(params.getAll('bar'));