admin管理员组文章数量:1422453
I'm playing around with the vue.js library, and I'm trying to make a change to the grid ponent example located here: .html
The sorting breaks when I add a space to one of the column names. See here: /
The column name gets passed through the sortBy function, which updates the sortKey variable to be the column name, and toggles the appropriate sortOrders key to be either -1 or 1.
sortBy: function (key) {
this.sortKey = key
this.sortOrders[key] = this.sortOrders[key] * -1
}
Does anyone know why this doesn't work? When I check the value of sortKey and sortOrders[key] they seem to be updating correctly. I think it must have something to do with not being able to use a space in the built in Vue.js orderBy filter. So it must break here:
<tr v-for="entry in data | filterBy filterKey | orderBy sortKey sortOrders[sortKey]">
<td v-for="key in columns">
{{entry[key]}}
</td>
</tr>
But I don't see anything in the Vue.js docs on how to fix this. Anyone have any ideas?
I'm playing around with the vue.js library, and I'm trying to make a change to the grid ponent example located here: http://vuejs/examples/grid-ponent.html
The sorting breaks when I add a space to one of the column names. See here: http://jsfiddle/greene48/9d1f0858/
The column name gets passed through the sortBy function, which updates the sortKey variable to be the column name, and toggles the appropriate sortOrders key to be either -1 or 1.
sortBy: function (key) {
this.sortKey = key
this.sortOrders[key] = this.sortOrders[key] * -1
}
Does anyone know why this doesn't work? When I check the value of sortKey and sortOrders[key] they seem to be updating correctly. I think it must have something to do with not being able to use a space in the built in Vue.js orderBy filter. So it must break here:
<tr v-for="entry in data | filterBy filterKey | orderBy sortKey sortOrders[sortKey]">
<td v-for="key in columns">
{{entry[key]}}
</td>
</tr>
But I don't see anything in the Vue.js docs on how to fix this. Anyone have any ideas?
Share Improve this question asked Nov 22, 2015 at 13:40 greenerrgreenerr 1193 silver badges10 bronze badges 2-
Is there any good reason for using a property name with spaces? Why not just use a
name_with_underscore
orcamelCase
? – matt_jay Commented Nov 22, 2015 at 13:42 - Well I wanted the column header name to have a space. But I suppose I could store the column header names in a separate object and access them using name_with_underscore as the key – greenerr Commented Nov 22, 2015 at 13:46
3 Answers
Reset to default 2One easy fix would be to replace key power value
with power_value
and then change the header manually after the Vue rendering using pure javascript like this
document.querySelectorAll('#demo thead th')[1].textContent = 'Power value';
Here is working jsfiddle
You should surround the sortKey
with square brackets,
orderBy [sortKey] sortOrders[sortKey]
http://jsfiddle/9d1f0858/2/
However, I agree to the above said to avoid to use property names with whitespaces.
I would suggest not making your property names dependent on the way you want them presented in your front end.
Use names that do not cause these issues as I suggested in my ment.
Your thought of mapping these names to an output value sounds reasonable.
You could even go as far as looking into the approaches described in this thread. Though that already creates constraints again.
本文标签: vuejsJavascript object keys with spacesStack Overflow
版权声明:本文标题:vue.js - Javascript object keys with spaces - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745366741a2655551.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论