私はデータベース呼び出しから作成しているjavascriptオブジェクトを持っています。複数の項目があり、特定のキー/値(moduleID)で参照できるようにする必要があります。代わりに私が探しています何を見つけるために、それぞれ1以上のループを有するのJavascriptオブジェクトでデータを見つける
success: function(data) {
// Define our local vars
var moduleIncludes = Array();
// Loop over each of the users selected modules and put them into an array
$(data).find('modules').each(function() {
// Push module JS file names to an array
moduleIncludes.push($(this).find('moduleJSFile').text());
// Create an object of module data
moduleData.push({
moduleID: $(this).find('moduleID').text(),
moduleRow: $(this).find('row').text(),
moduleColumn: $(this).find('col').text(),
moduleName: $(this).find('moduleName').text(),
moduleDescription: $(this).find('moduleDescription').text(),
moduleJSFile: $(this).find('moduleJSFile').text(),
moduleIcon: $(this).find('moduleIcon').text(),
moduleStartingXsize: $(this).find('startingXsize').text(),
moduleStartingYsize: $(this).find('startingYsize').text(),
moduleResizeLocked: $(this).find('resizeLocked').text(),
moduleMinXsize: $(this).find('minXsize').text(),
moduleMinYsize: $(this).find('minYsize').text()
});
});
// Using our array of modules, fetch them to include them into the page
$.getMultiScripts(moduleIncludes, 'includes/js/modules/').done(function() {
// All of the modules have been included. Trigger the grid functionality.
renderCanvas();
});
}
});
、私はそのユニークなので、代わりにmoduleID
ことで、オブジェクトに名前を付けることができます方法はありますか?
たとえば、moduleId 1に関連するすべてのデータを表示したい場合は、それをループするのではなく、IDでオブジェクトを検索するだけです。
私は作成時にこれを達成できますか?
「データ」の形式の例を表示できますか?あなたが配列を持っているなら、それをループするか( '.find()'や '.filter()')を使う必要がありますが、オブジェクトがあれば、キー名でプロパティを参照できます。 – nnnnnn
データは、ストアドプロシージャから渡されたXML文字列です。オブジェクトはイメージで見られるように細かく作成されていますが、IDで何らかの形で定義する必要があります。 – SBB