其中一个简单的人在我的头都受阻。我习惯于在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