divのリフレッシュを実現するために作成した空のjavascript配列(行列)があります。私は動的にデータを入れるための関数を作成しました。次に、Array(私は問題がある)を更新する関数を作成しました。 配列に格納されるデータは、JSONファイルに配置されるデータ属性です。配列の動的にJavaScript配列を更新するには
がvar currentAge = $(this).data("age");
var currentDate = $(this).data("date");
var currentFullName = $(this).data("fullname");
var currentIDPerson = $(this).data("idPerson");
var currentGender = $(this).data("gender");
作成:ここで
var arrayData = [];
機能を開始するために作成し、addindされ、より良いundertandに
、ここで私はJSONファイルに入れて、私のデータ属性は、配列への要素:
function initMatrix(p_currentIDPerson, p_currentGender, p_currentFullName, p_currentDate, p_currentAge) {
var isFound = false;
// search if the unique index match the ID of the HTML one
for (var i = 0; i < arrayData.length; i++) {
if(arrayData[i].idPerson== p_currentIDPerson) {
isFound = true;
}
}
// If it doesn't exist we add elements
if(isFound == false) {
var tempArray = [
{
currentIDPerson: p_currentIDPerson,
currentGender: p_currentGender,
currentFullName: p_currentFullName,
currentDate: p_currentDate, currentAge: p_currentAge
}
];
arrayData.push(tempArray);
}
}
ここでの更新関数はwhです私は試してみましたが、うまくいかず、おそらく私は正しい方法でコーディングしていません。もし助けてくれれば幸いです。 「$この」とニレを理解することが
function updateMatrix(p_currentIDPerson, p_currentGender, p_currentFullName, p_currentDate, p_currentAge) {
for (var i = 0; i < arguments.length; i++) {
for (var key in arguments[i]) {
arrayData[i] = arguments[i][key];
}
}
}
:ニレは、私がイベントをクリック入れclickableDivsです:
(function($) {
// Plugin to manage clickable divs
$.fn.infoClickable = function() {
this.each(function() {
var elm = $(this);
//Call init function
initMatrixRefresh(elm.attr("idPerson"), elm.data("gender"), elm.data("fullname"), elm.data("date"), elm.data("age"));
//call function update
updateMatrix("idTest", "Alarme", "none", "10-02-17 08:20", 10);
// Définition de l'evenement click
elm.on("click", function(){});
});
}
$('.clickableDiv').infoClickable();
}(jQuery));
は、私は結果の行列の形状を考えて、事前
あなたの助けてくれてありがとうございますが、私はリストではなく配列で作業する必要があります。同じロジック/コードですか? @マテウス – Zee
ねえ、@ Zee!なぜ配列は必須ですか?配列にする必要があるプラグインまたはAPIを使用していますか?そうでなければ、私はなぜオブジェクトを使用しない理由が表示されません... –
反射の後、私はあなたが言ったように厳密にしました。それは良いです...あなたの助けに感謝します(: – Zee