vue.js - Javascript object keys with spaces - Stack Overflow

I'm playing around with the vue.js library, and I'm trying to make a change to the grid ponen

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 or camelCase? – 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
Add a ment  | 

3 Answers 3

Reset to default 2

One 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745366742a4624615.html

相关推荐

  • vue.js - Javascript object keys with spaces - Stack Overflow

    I'm playing around with the vue.js library, and I'm trying to make a change to the grid ponen

    17小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信