其中一個簡單的人在我的頭都受阻。我習慣於在PHP和MySQL編碼,我只是無法弄清楚在C#中的簡單語法。C#團結下拉菜單,在變化調用一個函數,函數查詢列表返回匹配列表項
我有我的項目類如下結構持有企業名單列表。我有一個團結的下拉和我的onchange在使用這個所選項目的類別ID:
private void myDropdownValueChangedHandler(Dropdown target) {
int selectedIndex = myDropdown.value;
//LOAD THE ID FROM THE CATS LIST
string theName = myDropdown.options[selectedIndex].text;
var result = loadJSONCats.instance.fetchItemIDByName(theName);
}
public Item fetchItemByID(int id){
for (int i = 0; i < myList.Count; i++) {
if(myList[i].ID == id){
return myList[i];
}
}
return null;
}
我現在需要尋找在MYLIST匹配列表。
在MySQL我將選擇從MYLIST *其中term_id IN(ID);
我需要一個新的列表,從這樣我就可以遍歷項目中發現的結果創建和初始化一個預製,其將與各垂直行的正確數據的垂直列表元素。
我Item類
public class Item {
public int ID {get; set;}
public string post_modified {get; set;}
public string post_title {get; set;}
public string post_type {get; set;}
public string guid {get; set;}
public string Terms_IDs {get; set;}
public string City {get; set;}
public string Latitude {get; set;}
public string LogoID {get; set;}
public string Longitude {get; set;}
//public Item(int id, string post_mod, string post_title, string post_type, string terms, string meta, string guid){
public Item(int id, string post_mod, string post_title, string post_type, string guid, string terms, string city, string latitude, string logoID, string longitude){
this.ID = id;
this.post_modified = post_mod;
this.post_title = post_title;
this.post_type = post_type;
this.guid = guid;
this.Terms_IDs = terms;
this.City = city;
this.Latitude = latitude;
this.LogoID = logoID;
this.Longitude = longitude;
}
}
條款ID是一個字符串的json代碼是更容易這樣翻譯。
這是我卡上的功能,
public Item findItemsByIDs(int termID){
}
我需要在ID爲item.terms通過,並找到所有匹配的列表項:
public List<Item> myList = new List<Item>();
然後用正確的數據返回一個列表,並調用預製實例化來填充垂直網格,並在查詢中填充結果行。
我是新來的LINQ和與蘭巴之間感到困惑。
這只是其中的一個東西,我冷做很容易在SQL正常,但爲新的C#我去所有在互聯網上還是一無所獲快。
幫助讚賞。
這裏的構造函數:
void ConstructListingDatabase(){
for (int i = 1; i < itemData.Count; i++) {
myList.Add(new Item((int)itemData[i][0], itemData[i][1].ToString(), itemData[i][2].ToString(), itemData[i][3].ToString(), itemData[i][4].ToString(), itemData[i][5].ToString(), itemData[i][6].ToString(), itemData[i][7].ToString(), itemData[i][8].ToString(), itemData[i][9].ToString()));
}
}
感謝CNuts :) – Diego
@Diego不客氣:) – CNuts
@Diego我編輯了我的答案,你可以試試我認爲這可能是你正在尋找的。 – CNuts