简体   繁体   English

如何读取钛合金中的本地电话代码xml

[英]How to read local country phone codes xml in titanium alloy

In my application I get the country code using Titanium.Locale.getCurrentCountry(); 在我的应用程序中,我使用Titanium.Locale.getCurrentCountry();获得国家/地区代码。 , I then want to match this country code with this xml : https://code.google.com/p/country-phone-codes/ to find the corresponding country name and phone code. ,然后我要将此国家/地区代码与此xml相匹配: https : //code.google.com/p/country-phone-codes/以查找相应的国家/地区名称和电话代码。 I am using titanium alloy so where should I put this xml in my project and how can I parse this xml to get the country name and phone code required ? 我正在使用钛合金,因此我应该在项目中放置该xml,如何解析该xml以获取所需的国家/地区名称和电话代码?

I would just convert this to JSON (here is a fiddle, I did it for you) and put it inside a file called countries.js , put this file inside your app/lib/ folder (create it if it does not exist) and then call it from code like this: 我只是将它转换为JSON(这里是一个小提琴,我这么做是为了你) ,并把它称为文件中countries.js ,把这个文件里面的app/lib/文件夹(创建它,如果它不存在)和然后从这样的代码中调用它:

var countries = require('countries');
// Lookup the country name and phone code by country code
var name = countries['us'].name;
var phoneCode = countries['us'].phoneCode;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM