SearchField sapui5显示来自json的数据

时间:2016-11-18 04:06:27

标签: javascript json sapui5

我已将json数据绑定到sapui5中查看。但是我希望通过选择的id从json吐司中显示值。

JSON数据:

var data_suggest = [{"key":"1","value":"value dari 1", "description": "Satu"},
                    {"key":"2","value":"value dari 2", "description": "Dua"},
                    {"key":"3","value":"value dari 3", "description": "Tiga"}]

查看:

                <m:SearchField id="idSearchBy" 
                               enableSuggestions="true"
                               suggest="onSuggest" 
                               liveChange="onLiveChange"
                               search="onSearchBy"
                               placeholder="Search..."
                               suggestionItems="{
                                    path: 'suggest_model>/',
                                    sorter: {path : 'suggest_model>value'}
                               }">                  
                    <m:suggestionItems>
                        <m:SuggestionItem text="{suggest_model>value}" key="{suggest_model>key}"/>
                    </m:suggestionItems>    
                </m:SearchField>

我想在运行onSearchBy函数时,通过选定的id形式SearchField显示JSON中的值键,值和描述。

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

试试这个。它有效:

<SearchField
    id="idSearchBy"
    placeholder="Search for..."
    enableSuggestions="true"
    search="onSearch"
    suggest="onSuggest"
    suggestionItems="{
        path: '/suggest_model',
        sorter: { path: 'key' }
    }"
>
    <suggestionItems>
        <SuggestionItem text="{value}" key="{key}"/>
    </suggestionItems>
</SearchField>

您可以查看并下载example