本文的目的是介绍我已将对象数组传递给"value"属性,然后将该数组附加到状态,但未呈现为html的详细情况,我们将通过专业的研究、有关数据的分析等多种方式,同时也不会遗漏关于asp.net-mvc-
本文的目的是介绍我已将对象数组传递给
- 我已将对象数组传递给
- "value" 属性,然后将该数组附加到状态,但未呈现为 html
- asp.net-mvc-3 – 如何将int数组传递给RouteValueDictionary
- asp.net-mvc-3 – 将数组传递给RouteValues,并将其渲染为粘贴友好的URL
- c# – 将对象数组作为TempData []传递给视图
- javascript – 如何将对象数组附加到现有数组?
我已将对象数组传递给
如何解决我已将对象数组传递给 <li> "value" 属性,然后将该数组附加到状态,但未呈现为 html?
这是我想要呈现分配给 li 标签中的 value 属性的对应数据的数据在这里分配的状态,即在我的情况下为 otherState
const [otherDetails,setotherDetails] = React.useState([]);
const state = {
listitems: [
{
id: 1,vendorContact: "User 1",otherDetails: [
{
firstName: ''U'',lastName: ''I'',city: ''O'',zip: ''560084''
}
]
},{
id: 2,vendorContact: "User 2",otherDetails: [
{
firstName: ''D'',lastName: ''N'',city: ''W'',{
id: 3,vendorContact: "User 3",otherDetails: [
{
firstName: ''A'',lastName: ''B'',city: ''V'',zip: ''560084''
}
]
}
]
};
这里我必须在
<ul className="sidenavList">
{state.listitems.map(listitem => (
<li key={listitem.id} className="row" value={listitem.otherDetails} onClick={handleSelection}>
{listitem.vendorContact}
</li>
))}
</ul>
最后,这是我尝试使用 react 显示数据的地方
<div className="right"> {
<span>{otherDetails}</span>
}
</div>
更新偶数状态
const handleSelection = (e) => {
e.preventDefault();
setotherDetails(e.target.getAttribute(''value''))
}
解决方法
根据您的评论,我无法满足您的所有特定需求,但这里有一个基本实现,它为每个元素分配一个唯一的 Dim d As Range
For Each d In orng
Dim val As Range
Set val = adws.Range("O2:O" & lrw).Find(d.Value,xlValues,xlWhole).Offset(0,26)
If val Is Nothing Then
MsgBox d.Value & " not found."
End
Else
d.Offset(0,12) = val.Value
End If
Next
,然后可以在点击处理程序中使用它来检索适当的项目并用它更新状态。我不确定您对 id
变量的需求是什么,无论它们是作为道具出现还是应该作为自己的 state
元素进行管理。
useState
const App = () => {
const [otherDetails,setOtherDetails] = React.useState([]);
const state = { listitems: [{ id: 1,vendorContact: "User 1",otherDetails: [{ firstName: ''U'',lastName: ''I'',city: ''O'',zip: ''560084'' }] },{ id: 2,vendorContact: "User 2",otherDetails: [{ firstName: ''D'',lastName: ''N'',city: ''W'',{ id: 3,vendorContact: "User 3",otherDetails: [{ firstName: ''A'',lastName: ''B'',city: ''V'',zip: ''560084'' }] }] };
const handleSelection = (e) => {
const targetItem = state.listitems.find(({ id }) => id == e.target.id)
setOtherDetails(targetItem.otherDetails)
}
return (
<div>
<ul className="sidenavList">
{state.listitems.map(listitem => (
<li key={listitem.id} id={listitem.id} className="row" onClick={handleSelection}>
{listitem.vendorContact}
</li>
))}
</ul>
{otherDetails.length ?
<div className="right">
{otherDetails.map(detail => (
Object.entries(detail).map(([key,val]) => (
<p>{key}<span> {val}</span></p>
))
))}
</div>
: null}
</div>
)
}
ReactDOM.render(
<App />,document.getElementById("root")
);
asp.net-mvc-3 – 如何将int数组传递给RouteValueDictionary
我尝试着:
var routeData = new RouteValueDictionary(); routeData.Add("GroupId","1,2");
得到:GroupId = 1,2
要么
routeData.Add("GroupId","1"); routeData.Add("GroupId","2");
获取:已添加具有相同键的项目
乃至
routeData.Add("GroupId[0]","1"); routeData.Add("GroupId[1]","2");
得到:?GroupId [0] = 1& GroupId [1] = 2
有可能以某种方式修复我的问题?
解决方法
public static string Buildpath(RequestContext context,string routeName,RouteValueDictionary routeValues,object additionalParams) { var vpd = RouteTable.Routes[routeName].GetVirtualPath(context,routeValues); if (vpd == null) return string.Empty; var virtualpath = vpd.VirtualPath; var addparams = BuildAdditionalParams(additionalParams); if (!virtualpath.Contains("?") && addparams.Length > 0) virtualpath = virtualpath + "?" + addparams; else if (virtualpath.Contains("?") && addparams.Length > 0) virtualpath = virtualpath + "&" + addparams; return "/" + virtualpath; } protected static string BuildAdditionalParams(object additionalParams) { if (additionalParams == null) return string.Empty; StringBuilder sb = new StringBuilder(); Type type = additionalParams.GetType(); PropertyInfo[] props = type.GetProperties(); Action<string,string> addProperty = (name,value) => { if (sb.Length > 0) sb.Append("&"); sb.Append(name); sb.Append("="); sb.Append(value); }; foreach (PropertyInfo prop in props) { var simplevalue = prop.GetValue(additionalParams,null); if (simplevalue != null) { Type propertyType = prop.PropertyType; if (Nullable.GetUnderlyingType(propertyType) != null) { propertyType = Nullable.GetUnderlyingType(propertyType); } if (propertyType.IsEnum) { addProperty(prop.Name,((int)simplevalue).ToString()); } else if (propertyType.IsArray && propertyType != typeof(string)) { foreach (var val in prop.GetValue(additionalParams,null) as IEnumerable) addProperty(prop.Name,val.ToString()); } else { if (!string.IsNullOrEmpty(simplevalue.ToString())) addProperty(prop.Name,simplevalue.ToString()); } } } return sb.ToString(); }
此函数将构建路径的完整路径,并将additionalParams对象中的值作为查询字符串数据附加.这可以通过执行其ToString方法来处理数组,枚举,可空值和其他类型.
希望这可以帮助!
asp.net-mvc-3 – 将数组传递给RouteValues,并将其渲染为粘贴友好的URL
例如,说我有这样的动作:
public ActionResult Index(ICollection<int> ids) { ...do something }
在我的模板中,我做了这样的事情:
@Url.Action("Index",routeValues:new int[]{1,2,3})
目标是拥有一个这样的url输出:
... /index?ids=1&ids=2&ids=3
但是url输出实际上是这样的:
... /index?ids=system.int[]
我假设目前没有任何支持.如果没有,那么在MVC的哪个部分我需要创建一个自定义处理程序或什么来覆盖这个默认功能?
解决方法
@(Url.Action("Index") + "?" + string.Join("&",new int[] { 1,3 }.Select(x => "ids=" + x)))
或者写一个扩展方法来封装逻辑:
@Url.ActionWithIds("Index",3 })
由于这些都是整数,所以我们不需要url编码,但是如果要对字符串集合做同样的事情,这些值应该被正确的url编码.
c# – 将对象数组作为TempData []传递给视图
我想在成功消息中显示用户刚保存的图像的小缩略图和已保存项目的标题.
目前我将所有数据作为新的MvcHtmlString传递
TempData["SaveMsg"] = new MvcHtmlString("<img src=" + model.ImageUrl + " //> <h3//>" + model.Name + " has been saved.<//h3//> " ) ;
我想把它作为对象发送[]
TempData["SaveMsg"] = new object[]{model.ImageUrl,model.Name}
然后我就可以将对象传递给HtmlHelper并编写消息显示的条件.
我只是不知道如何访问视图中的对象
@TempData["SaveMsg"][0] // (O.o) // Error Cannot apply indexing with // [] to an expression of type 'object'
这甚至可能吗?
解决方法
@{ var objectArray = (object[]) TempData["SaveMsg"]; } @objectArray[0] @objectArray[1]
.Net fiddle
javascript – 如何将对象数组附加到现有数组?
> How to extend an existing JavaScript array with another array,without creating a new array16个
> How to merge two arrays in JavaScript and de-duplicate items71个
我创建了以下数组:
$scope.testAccounts[0] = { id: 99,name: "Select Account" };
我试过了
$scope.testAccounts.push(result.data);
其中results.data看起来像这样:
[{ id: 1,name: "x" },{ id: 2,name: "y" }]
但是,这似乎不起作用,因为它试图添加一个数组作为第二个元素.我需要的是将数组result.data的内容附加到数组$scope.testAccounts
请注意,如果数组是一个对象数组,到目前为止我看到的所有示例似乎都不起作用.这就是我所拥有的.谢谢
解决方法
> foo = [1,2,3] [1,3] > foo.concat([4,5,6]) [1,3,4,6]
今天关于我已将对象数组传递给
本文标签: