Skip to content

Commit a7cb4ac

Browse files
committed
[BUGFIX beta] Allow numeric keys for the get keyword
Fixes #13296
1 parent eeb236e commit a7cb4ac

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

packages/ember-glimmer/lib/utils/references.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ export class PropertyReference extends CachedReference { // jshint ignore:line
127127
}
128128

129129
get(propertyKey) {
130+
if (typeof propertyKey === 'number') {
131+
// Allows us to get numeric keys
132+
propertyKey = '' + propertyKey;
133+
}
134+
130135
return new PropertyReference(this, propertyKey);
131136
}
132137
}

packages/ember-glimmer/tests/integration/helpers/get-test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,31 @@ moduleFor('Helpers test: {{get}}', class extends RenderingTest {
5151
this.assertText('[red and yellow] [red and yellow]');
5252
}
5353

54+
['@test should be able to get an object value with numeric keys']() {
55+
this.render(`{{#each indexes as |index|}}[{{get items index}}]{{/each}}`, {
56+
indexes: [1, 2, 3],
57+
items: {
58+
1: 'First',
59+
2: 'Second',
60+
3: 'Third'
61+
}
62+
});
63+
64+
this.assertText('[First][Second][Third]');
65+
66+
this.runTask(() => this.rerender());
67+
68+
this.assertText('[First][Second][Third]');
69+
70+
this.runTask(() => set(this.context, 'items.1', 'Qux'));
71+
72+
this.assertText('[Qux][Second][Third]');
73+
74+
this.runTask(() => set(this.context, 'items', { 1: 'First', 2: 'Second', 3: 'Third' }));
75+
76+
this.assertText('[First][Second][Third]');
77+
}
78+
5479
['@test should be able to get an object value with a bound/dynamic key']() {
5580
this.render(`[{{get colors key}}] [{{if true (get colors key)}}]`, {
5681
colors: { apple: 'red', banana: 'yellow' },

packages/ember-htmlbars/lib/keywords/get.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ const DynamicKeyStream = BasicStream.extend({
3737
let key = this.keyDep.getValue();
3838
if (typeof key === 'string') {
3939
return key;
40+
} else if (typeof key === 'number') {
41+
return '' + key;
4042
}
4143
},
4244

0 commit comments

Comments
 (0)