将 dijit.InlineEditBox 与 dijit.form.Select 结合使用
我正在尝试使用 dijit.form.Select 作为我的 dijit.InlineEditBox 的编辑器。似乎发生了两个问题/意外行为:
- 不一致,InLineEditBox 没有将初始值设置为选定的
- 一致,选择一个选项后,显示应隐藏的值而不是标签。
- 宽度未设置为 130px
这是工作代码: http://jsfiddle.net/mimercha/Vuet8/ 7/
要点
<span dojoType="dijit.InlineEditBox" editor="dijit.form.Select"
editorParams="{
options: [
{label:'None',value:'none'},
{label:'Student',value:'stu'},
{label:'Professor',value:'prof',selected:true},
],
style:'width:1000px;',
}"
editorStyle="width: 1000px;"
>
</span>
非常感谢任何帮助!谢谢!
I'm trying to use a dijit.form.Select as the editor for my dijit.InlineEditBox. Two problems / unexpected behavior seem to occur:
- Inconsistently, the InLineEditBox doesn't have the initial value set as selected
- Consistently, after selecting a choice, the value that should be hidden is shown instead of the label.
- The width isn't set to 130px
Here's working code: http://jsfiddle.net/mimercha/Vuet8/7/
The jist
<span dojoType="dijit.InlineEditBox" editor="dijit.form.Select"
editorParams="{
options: [
{label:'None',value:'none'},
{label:'Student',value:'stu'},
{label:'Professor',value:'prof',selected:true},
],
style:'width:1000px;',
}"
editorStyle="width: 1000px;"
>
</span>
Any help is greatly appreciated! Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好吧,在与
dijit.InlineEditBox
的混乱斗争了几个小时之后,我想我已经解决了剩下的问题 (#2)。编辑:我对 #2 的第一个解决方案仍然有缺陷; http://jsfiddle.net/kfranqueiro/Vuet8/10/ 的实现永远不会返回调用 get('value') 时的实际内部值。
编辑#2:我修改了解决方案,以便该值仍然保留真实(隐藏)值,使 displayedValue 保持独立。看看这是否效果更好:
http://jsfiddle.net/kfranqueiro/Vuet8/13/
首先,为那些没有使用 IRC 的人回顾一下:
问题 #1 的发生是由于值没有正确设置为 InlineEditBox 本身的顶级属性;它没有从包装的小部件中正确拾取它。
问题 #3 的发生是由于 InlineEditBox 执行一些非常疯狂的逻辑来尝试解析样式。事实证明,InlineEditBox 通过将其公开为顶级数字属性,使设置宽度变得特别容易。 (尽管 IINM 您也可以将百分比指定为字符串,例如“50%”)
现在,问题#2...这就是杀手。问题是,虽然 InlineEditBox 似乎有一些逻辑来解释具有
displayedValue
属性的小部件,但该逻辑有时是错误的(它需要一个displayedValue
code> 属性实际存在于小部件上,但情况不一定如此),而其他时候则完全缺失(当 InlineEditBox 初始化时)。我已经在自己的 InlineEditBox 及其使用的内部小部件 _InlineEditor 的 dojo.declare 扩展中尽我所能地解决了这些问题 - 因为通常最好保持原始发行版不变。它并不漂亮(我为理解并提出这一点而挖掘的底层代码也不是),但它似乎正在完成它的工作。
但是伙计,这很有趣。并且也可能与我的兴趣相关,因为我们也在 UI 中使用了这个小部件,并且将来会更多地使用它。
如果有什么适得其反的事情请告诉我。
Okay, after a few MORE hours struggling with the mess that is
dijit.InlineEditBox
, I think I have the solution to the remaining issue (#2).EDIT: My first solution to #2 is still flawed; the implementation at http://jsfiddle.net/kfranqueiro/Vuet8/10/ will never return the actual internal value when get('value') is called.
EDIT #2: I've revamped the solution so that value still retains the real (hidden) value, keeping displayedValue separate. See if this works better:
http://jsfiddle.net/kfranqueiro/Vuet8/13/
First, to recap for those who weren't on IRC:
Issue #1 was happening due to value not being properly set as a top-level property of the InlineEditBox itself; it didn't pick it up properly from the wrapped widget.
Issue #3 was happening due to some pretty crazy logic that InlineEditBox executes to try to resolve styles. Turns out though that InlineEditBox makes setting width particularly easy by also exposing it as a top-level numeric attribute. (Though IINM you can also specify a percentage as a string e.g. "50%")
Now, issue #2...that was the killer. The problem is, while InlineEditBox seems to have some logic to account for widgets that have a
displayedValue
attribute, that logic is sometimes wrong (it expects adisplayedValue
property to actually exist on the widget, which isn't necessarily the case), and other times missing entirely (when the InlineEditBox initializes). I've worked around those as best I could in my owndojo.declare
d extensions to InlineEditBox and the internal widget it uses, _InlineEditor - since generally it's a good idea to leave the original distribution untouched.It's not pretty (neither is the underlying code I dug through to understand and come up with this), but it seems to be doing its job.
But man, this was rather interesting. And potentially pertinent to my interests as well, as we have used this widget in our UIs as well, and will be using it more in the future.
Let me know if anything backfires.
嗯...
另外,当使用 dijit.form.Select 时,选定的值不是 attr“selected”而是值。
如果您在
内输入 prof prof
比您正确选择的选项将被选择;)Dijit select 检查 VALUE,而不是 attr。
hm...
Also, when using dijit.form.Select, selected value is not attr "selected" but value.
And if you enter prof inside
<span ...blah > prof </span>
than your proper selected option will be selected ;)Dijit select checks for VALUE, not attr.
这可能在最近的 Dojo 中得到修复 - 请参阅 http://bugs.dojotoolkit.org/ticket/15141 - 但使用 1.7.3 我发现这有效:
在我的应用程序目录中,与 dojo、dijit 和 dojox 处于同一级别,我创建了一个文件 InlineSelectBox.js,它使用代码扩展了 InlineEditBox,以在关联的 domNode 上设置 HTML Dijit 的值,并将该代码连接到 onChange() 事件:
然后,在我的视图脚本中:
This may be fixed in recent Dojo - see http://bugs.dojotoolkit.org/ticket/15141 - but using 1.7.3 I found this worked:
In my app directory, at the same level as dojo, dijit and dojox, I created a file InlineSelectBox.js which extends InlineEditBox with code to set the HTML on the associated domNode from the value of the Dijit, and which wires up that code to the onChange() event:
Then, in my view script:
几个月前我正在处理这种情况,但没有找到解决方案,我制定了自己的算法。
我在 Onclick 上放置了一个带有事件的 div,该事件以编程方式在该 div 上构建了一个带有我想要使用的商店的过滤选择。
我使用 onBlur 事件来销毁小部件,并使用 onchange 来通过 xhr 保存新值。
焦点位于下方,因为 onBlur 无法正常工作。
注意:功能尚不完整。
I was dealing with this situation a few months ago, and not finding a resolution i made my own algorithm.
I put a div with an event on Onclick that build programatically a Filtering Select on that div with the store i want to use.
I used the onBlur event to destroy the widget and the onchange to save by xhr the new value.
The focus is below because the onBlur was not working properly.
note: the function is not complete.