如何对给定的示例进行排序。
IEnumerable<extra> eList = new List<extra>()
{
new extra{ id = 1, text = "a"},
new extra{ id = 2, text = "g"},
new extra{ id = 3, text = "i"},
new extra{ id = 4, text = "e"},
new extra{ id = 5, text = "f"},
new extra{ id = 6, text = "d"},
new extra{ id = 7, text = "c"},
new extra{ id = 8, text = "h"},
new extra{ id = 9, text = "b"}
}; …Run Code Online (Sandbox Code Playgroud) 我有一个调用函数的代码,如下所示:
this.getAllOptions(questionID);
console.log("++++++++++++++++++++++++++++++++");
console.log(this.result);
Run Code Online (Sandbox Code Playgroud)
该函数非常简单,它调用一个返回对象数组的服务。从返回的数据来看,我只需要字符串格式的“item.Content”,如下所示。
result: string;
getAllOptions(question_ID){
this.result = "";
this._service.getOptionsQuestion(question_ID)
.subscribe( data => {
data.forEach(item => {
console.log(item.Content);
this.result += item.Content;
});
});
}
Run Code Online (Sandbox Code Playgroud)
但问题是,调用函数“getAllOptions()”之后的代码首先被执行。我希望调用方法后的代码等待函数完成执行。
那可能吗?
可以将多行连接到一行吗?
例如:
IEnumerable<sample> sam = new List<sample>()
{
new sample{ id = 1, name = "sample 1", list = new List<int>{1,5,6}},
new sample{ id = 2, name = "sample 2", list = new List<int>{2,9}},
new sample{ id = 3, name = "sample 3", list = new List<int>{8,3,7}},
new sample{ id = 4, name = "sample 4", list = new List<int>{3,4,8}},
new sample{ id = 5, name = "sample 5", list = new List<int>{1,5,7}},
new sample{ id = 6, name = …Run Code Online (Sandbox Code Playgroud)