[英]Can I access a C# Tuple value in Vue.js code?
So here's the question, can you access returned C# Tuple variables in vue.js? 所以这是问题,您可以在vue.js中访问返回的C#元组变量吗?
Example, I have a vue.js function that on a refresh calls a C# action ('GetChartData') which returns a json result to it. 例如,我有一个vue.js函数,该函数在刷新时调用C#动作(“ GetChartData”),该动作将向其返回json结果。
refreshChart: function () {
var vm = this;
$.getJSON(window.chartDataRoute, {
fromDate: (somedate),
toDate: (somedate)
}).done(function (data) {
vm.chartData = data;
});
},
So the json result of the C# function gets passed as a ContentResult type into vm.chartData in the vue.js code. 因此,C#函数的json结果作为ContentResult类型传递到vue.js代码中的vm.chartData中。 Here's the C# function:
这是C#函数:
public ContentResult GetChartData(DateTime? fromDate, DateTime? toDate)
{
var pageStats = (go away and get some data);
var chartModel = ChartHelpers.GetMainChartModel(chartPeriod, pageStats);
var json = JsonConvert.SerializeObject(chartModel, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
return new ContentResult { Content = json, ContentType = "application/json" };
}
All pretty straighforward, but I need to return two new fields to the vue.js function, and I really don't want to get involved with rewriting the json result as the results are used in a graph function that is beyond the scope of what I'm trying to do. 一切都很简单,但是我需要将两个新字段返回给vue.js函数,而且我真的不想参与重写json结果,因为结果被用于超出函数范围的graph函数中我在努力
So, can I convert the function to a Tuple and pass two extra int values and then access them in the vue.js code? 因此,我可以将函数转换为元组并传递两个额外的int值,然后在vue.js代码中对其进行访问吗? Like this:
像这样:
public Tuple<ContentResult,int,int> GetChartData(DateTime? fromDate, DateTime? toDate)
{
var pageStats = (go away and get some data);
var totalClicks = (an int number);
var totalViews = (an int number);
var chartModel = ChartHelpers.GetMainChartModel(chartPeriod, pageStats);
var json = JsonConvert.SerializeObject(chartModel, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
// Can I return the extra data in a Tuple?
return Tuple.Create(new ContentResult { Content = json, ContentType = "application/json" }, totalClicks, totalViews);
}
However, this breaks the vue.js, as I suppose 'data' is now different and so the graphs don't work. 但是,这破坏了vue.js,因为我认为“数据”现在不同了,因此图形不起作用。 So I'd need to be able to assign the ContentResult to data (as it is now), and the two extra ints somehow.
因此,我需要能够将ContentResult分配给数据(现在是这样), 并以某种方式将两个额外的int赋值。
If I can't do it like this then can I do it another way that doesn't involve rewriting any of the vue.js in depth? 如果我不能这样做,那么我可以做另一种不涉及深度重写任何vue.js的方法吗? One of problems is that I'm a bit of a vue.js novice...
问题之一是我有点vue.js新手...
Call the C# function twice one for chartdata and other for the other two properties. 两次调用C#函数,一次用于chartdata,另一次用于其他两个属性。 you also need to pass some Identifier for which the C# function get called either for chartdata or other two properties.
您还需要传递一些标识符,以获取ChartData或其他两个属性的C#函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.