有人可以向我解释如何将此内部js更改为外部。如果文件中有某些内容未显示它是另一个文档,但我确实需要提及的所有ID和类别
private void showEmployee() {
JSONObject jsonObject = null;
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
try {
jsonObject = new JSONObject(JSON_STRING);
JSONArray result = jsonObject.getJSONArray(Config.TAG_JSON_ARRAY);
for (int i = 0; i < result.length(); i++) {
JSONObject jo = result.getJSONObject(i);
String id = jo.getString(Config.TAG_ID);
String name = jo.getString(Config.TAG_NAME);
String price = jo.getString(Config.TAG_PRICE);
HashMap<String, String> employees = new HashMap<>();
employees.put(Config.TAG_ID, id);
//employees.put(Config.TAG_ID2, "ID: " + id);
employees.put(Config.TAG_NAME, "Product name: " + name);
employees.put(Config.TAG_PRICE, "Price: ($)" + price);
list.add(employees);
}
} catch (JSONException e) {
e.printStackTrace();
}
ListAdapter adapter = new SimpleAdapter(
ViewAllStock.this, list, R.layout.list_item,
new String[]{ Config.TAG_ID, Config.TAG_NAME, Config.TAG_PRICE},
new int[]{ R.id.id, R.id.name, R.id.price});
listView.setAdapter(adapter);
}
答案 0 :(得分:0)
不确定这是您想要的,但我会在您的HTML中使用此函数调用替换script
标记的内容
<script>
initToggle();
</script>
然后在你的tlm-scripts.js
文件中,我将定义函数,如下所示:
$(document).ready(function(){
/// here goes your existing code on that file
/// if they are related to jquery
//...
//...
// define function that does the toggle
var initToggle = function(){
var bodyEl = $('body'),
navToggleBtn = bodyEl.find('.nav-toggle-btn');
navToggleBtn.on('click', function(e) {
bodyEl.toggleClass('active-nav');
e.preventDefault();
});
};
});
最后,在 您的Jquery文件后包含您的自定义JS文件
<强>更新强>
如果您不想在HTML页面上使用JS,请将函数声明更改为:
$(document).ready(function(){
/// here goes your existing code on that file
/// if they are related to jquery
//...
//...
// define function that does the toggle
var initToggle = function(){
var bodyEl = $('body'),
navToggleBtn = bodyEl.find('.nav-toggle-btn');
navToggleBtn.on('click', function(e) {
bodyEl.toggleClass('active-nav');
e.preventDefault();
});
};
// invoke function here, not in the HTML
initToggle();
});