English 中文(简体)
• 如何将选定名单与SproutCore 2.0和Handlebars联系起来
原标题:How to bind a select list with SproutCore 2.0 and Handlebars

考虑到以下的SC: 观点:

var view = SC.View.create({
  templateName:  people ,
  people: [],
  selectedPersonId: null});

以及以下人员手法模板:

<select>
  {{#each people}}
  <option {{bindAttr id="id"}}>{{name}}</option>
  {{/each}}
</select>

将选定的PersonId与选定名单挂钩的最佳方式是什么?

(@stackoverflow:Reputation of 1500+ to establish new tags?) 实际情况?

问题回答

您不妨就此形成一种习俗观点。 我使用在咖啡厅实施,基本上看上像这样的文字。

MyApp.SelectionView = SC.CollectionView.extend
    tagName:  select 
    value: null

    willInsertElement: ->
        @_elementValueDidChange()

    change: ->
        @_elementValueDidChange()

    _elementValueDidChange: ->
        views = SC.View.views
        selectedOptions = @$( option:selected )
        ### Multiple selections
        @set( value , selectedOptions.toArray().map( (el) ->
            SC.get(views[el.id],  content )
        ))
        ###
        @set( value , SC.get(views[selectedOptions.prop( id )],  content ))

由于你很容易发现,这是单一选择。 利用评论的代码将这一标准升级为多种选择。

也有关于选择观点的拉动要求(尽管由于作者没有使用新的甲型六氯环己烷代码而关闭了这种观点),见。 如果你仍然坐在桌旁,那么这封信应该为你提供甄选功能。





相关问题
sproutcore vs javascriptMVC for web app development

I want to use a javascript framework with MVC for a complex web application (which will be one of a set of related apps and pages) for an intranet in a digital archives. I have been looking at ...

sproutcore or cappucino for web app development?

I recently found out about the sproutcore and capuccino frameworks for web app development as proper MVC approach to creating Desktop-like applications. As far as I could understand, the main ...

Sproutcore: Changing css properties on mouse events

In sproutcore I m trying to change the border thickness of a div when a user mouses over it. All the other code is working but I can t find how to either access the css properties directly or attach ...

Sproutcore: adding a custom stylesheet or script

I just can t seem to find a good tutorial on this. It s simple: I want to link a stylesheet / js file to the HEAD section of my application. I found where the index.html file is (in tmp/build/static/...

Which web application framework? [closed]

From the following list of frameworks, which one would you use to develop a rich web application and why would you choose it over the others? Sproutcore GWT ExtJS GXT SmartGWT Dojo / Dijit Flex ...

Specific URLs with SproutCore

I m creating an application in SproutCore, which I want to integrate with Facebook. To do this, I need to create a file called xd_receiver.htm at / (see http://wiki.developers.facebook.com/index.php/...

热门标签