选择表中的行并显示详细信息
当用户单击行时,我想在输入中显示数据,以便它可以编辑(不想在表中编辑)
以下是代码: http://jsfiddle.net/APzK8/
就像你可以看到两个输入有效,两个无效。我希望 ViewModel 中只有 Selected 属性。在实际代码中,每个 Config 将具有 15-20 个属性。
另外,如果您可以帮助我在页面加载时选择第一个配置。我可以用 javascript 单击该行,但它很难看。我认为它应该在视图模型中定义。尝试了很多事情但没有任何效果。
When user clicks row I want to display data in inputs so it is editable (don't want editing in table)
Here is the code:
http://jsfiddle.net/APzK8/
Like you can see two inputs work and two don't. I'd prefer to have only Selected property in ViewModel. In real code every Config will have 15-20 properties.
Also if you could help me selecting first Config on page load. I can click the row with javascript but it is ugly. I think it should be defined in viewmodel. Tried many things but nothing worked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,您需要通过执行
Selected().Name
而不是Selected.Name
来访问这些值。因此,您想要获取 selected 的基础值,然后访问其Name
属性。然而,更简单/更好的方法是使用
with
控制流绑定,这将保护您免受空值的影响(避免必须编写Selected() ? Selected().名称:null
类型的语句)。它看起来像:
这是一个示例: http://jsfiddle.net/rniemeyer/APzK8/2/
为了选择第一个配置,我刚刚将
Selected
初始化为Configs
中的第一个值。Basically, you would need to access the values by doing
Selected().Name
rather thanSelected.Name
. So, you want to get the underlying value of selected and then access itsName
property.However, an easier/better way to do this is to use the
with
control-flow binding, which will protect you against null values (avoid having to writeSelected() ? Selected().Name : null
kind of statements).It would look like:
Here is a sample: http://jsfiddle.net/rniemeyer/APzK8/2/
To select the first config, I just initialized
Selected
to the first value inConfigs
.