讓 YUI DataTable 使用 JSON Data Over XHR 時支援中文 field

原由

YUI 真是個好東西,最近拿它來寫公司的程式。
天殺的! 不知以前是誰把資料庫欄位都用中文命名。
我輸出 JSON 長這樣...


{
 "ResultSet": {
  "Result": [{
   "ID": "1234",
   "姓名": "林洵賢",
   "電話": "1234567890"

... 省略

話說當今瀏覽器 UTF8 編碼的頁面 JavaScript 運作起來是沒什麼問題。
但 YUI 是外國人設計的,用它的 DataSource 抓資料後認為這些以中文為 key 的是壞東西會自動被忽略。


解決

追程式囉! 我原本是用 DataTable 當然從它開始追,追到另一個模組 DataSource 找到了!
我用的是 YUI 2.9 版,修改 \build\datasource\datasource*.js 原始程式,把

[^\w\.\$@]

改成

[^\w\.\$@\u4e00-\u9fa5]

就支援中文 key 了。


或許這篇算是寫給自己的筆記,沒接觸過的應該看沒有。
如果你不幸也在找同樣的解決方案 google 到我,那恭喜你囉,留個言吧!


後記
後來發現欄位排序中文Key也有問題,要修改 datatable*.js 尋找 [^\w\-] 改為 [^\w\-\u4e00-\u9fa5] 即可。

24 個回應:

chenmeinv0 提到...

north face jackets
moncler coats
fitflop shoes
ugg outlet
ray ban outlet
canada goose sale
nike tn pas cher
michael kors outlet
oakley sunglasses outlet
pandora jewelry
2016.10.27xukaimin

chenlina 提到...

ralph lauren
oakley sunglasses canada
north face jackets
ugg boots
ray ban wayfarer
cheap basketball shoes
nike air max
cheap mlb jerseys
coach outlet
nike roshe run
chenlina20170109

chenlina 提到...

coach outlet
oakley sunglasses wholesale
ralph lauren uk
louis vuitton outlet online
gucci shoes
michael jordan shoes
clarks shoes
polo ralph lauren
rolex datejust
hermes uk
chenlina20170720

Anonymous 提到...

Now, if you are the registered employee or an authorized associate working for one of the largest banking institutions in the country and want to access Bank of America Employee Benefits info or register at BofA Resources At Home website then get easy instructions shown below now. 메이저사이트

Anonymous 提到...

Now, if you are the registered employee or an authorized associate working for one of the largest banking institutions in the country and want to access Bank of America Employee Benefits info or register at BofA Resources 스포츠사이트

Anonymous 提到...

if you are the registered employee or an authorized associate working for one of the largest banking institutions in the country and want to access Bank of America Employee Benefits info or register 사설토토

Anonymous 提到...

employee or an authorized associate working for one of the largest banking institutions in the country and want to access Bank of America Employee Benefits info 먹튀검증사이트

Anonymous 提到...

authorized associate working for one of the largest banking institutions in the country and want to access Bank of America Employee Benefits 안전놀이터

Anonymous 提到...

Now, if you are the registered employee or an authorized associate working for one of the largest banking institutions in the country and want to access Bank of America Employee 토토사이트

Anonymous 提到...

if you are the registered employee or an authorized associate working for one of the largest banking institutions in the country and want to access Bank of America Employee Benefits info or register 먹튀폴리스

Anonymous 提到...

It is great to have visited your website. Thanks for sharing useful information. And also visit my website about health. God willing it will be useful too 스포츠사이트

Anonymous 提到...

if you are the registered employee or an authorized associate working for one of the largest banking institutions in the country and want to access Bank of America Employee Benefits 메이저사이트

Anonymous 提到...

employee or an authorized associate working for one of the largest 먹튀검증

온라인카지노사이트 提到...

온라인카지노사이트 Hello! This is my first visit to your blog! We are a group of volunteers and starting a
new initiative in a community in the same niche. Your blog provided us
valuable information to work on. You have done a marvellous
job!

메이저사이트 목록 提到...

메이저사이트 Hi, just wanted to say, I loved this post. It was practical. Keep on posting!

BESTSITE 提到...

Interesting stuff to read. Keep it up. This is very informative and interesting for those who are interested in blogging field.

야한동영상

CLICKME 提到...

"Undeniably imagine that which you stated. Your favorite reason seemed to be at the net the easiest factor to take note of. I say to you, I definitely get irked at the same time as people consider issues that they just do not recognize about. You controlled to hit the nail upon the highest and also defined out the entire thing with no need side effect, other people can take a signal. Will likely be again to get more. Thank you 오피"

MY SITE 提到...

Enjoyed reading the article above , really explains everything in detail, the article is very interesting and effective. Thank you and good luck for the upcoming articles.

외국인출장

Majortotosite Pro 提到...

Thanks for such a great post and the review, I am totally impressed! Keep stuff like this coming. 메이저사이트

Racesite Pro 提到...

I have a hard time describing my thoughts on content, but I really felt I should here. Your article is really great. I like the way you wrote this information
온라인경마
경마사이트


Oncasinosite Net 提到...

It was my excitement discovering your site last night. I came here now hoping to find out interesting things. I was not dissatisfied. Your ideas for new methods on this subject were useful and an excellent help to myself. 바카라사이트

uillyacfabian 提到...

Stilletto Titanium Hammer Stainless Steel-Plated Double Edge
Stilletto Titanium Hammer titanium price Stainless Steel-Plated Double Edge Razor Blade · 4”- Sterling sia titanium stainless titanium gravel bike steel, 4-Piece, 3.0 titanium white acrylic paint oz., 10 titanium pots and pans

匿名 提到...

he648 louis vuitton outlet,louis vuitton outlet,louis vuitton outlet,louis vuitton outlet,louis vuitton outlet,louis vuitton outlet dq592

my replica store 提到...

The best replica bags website in 2024My Replica Store , replica bags , AAA replica bags , ysl replica bag and so on.dfe52

張貼留言