Last active
April 1, 2016 11:58
-
-
Save kempei/1cb6cc606f23317b768bedb50ef77743 to your computer and use it in GitHub Desktop.
JET+oj.Collectionを使用したリモートフェッチ ref: http://qiita.com/kempe/items/dc16ba24ccf3ed52b4d2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://localhost:8080/api/item/list?totalResults=true&limit=3&offset=0 | |
http://localhost:8080/api/item/list?totalResults=true&limit=3&offset=3 | |
http://localhost:8080/api/item/list?totalResults=true&limit=3&offset=6 | |
http://localhost:8080/api/item/list?totalResults=true&limit=3&offset=9 | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul id="itemList" aria-label="item list using oj.collection" style="height:100%" | |
data-bind="ojComponent: { | |
component: 'ojListView', | |
data: itemDataSource, | |
item: {template: 'item_template'}, | |
selectionMode: 'single', | |
rootAttributes: {style: 'width:100%;height:200px;overflow-x:hidden'}, | |
scrollPolicy: 'loadMoreOnScroll', | |
scrollPolicyOptions: {fetchSize: 3} | |
}"> | |
</ul> | |
<script type="text/html" id="item_template"> | |
<li data-bind="attr: {id: itemId}"> | |
<div class="oj-flex" style="flex-wrap: nowrap"> | |
<div class="oj-flex-item"> | |
<div> | |
<strong data-bind="text: itemName"/> | |
<span data-bind="text: itemDesc"/> | |
</div> | |
</div> | |
</div> | |
</li> | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(['ojs/ojcore', 'knockout', 'jquery', 'ojs/ojknockout', | |
'promise', 'ojs/ojlistview', 'ojs/ojcollectiontabledatasource', 'ojs/ojmodel'], | |
function (oj, ko, $) { | |
function ListViewModel() { | |
var self = this; | |
var itemModel = oj.Model.extend({ | |
idAttribute: 'itemId' | |
}); | |
var itemCollection = new oj.Collection(null, { | |
url: 'http://localhost:8080/api/item/list', | |
fetchSize: 3, | |
model: itemModel | |
}); | |
self.itemDataSource = new oj.CollectionTableDataSource(itemCollection); | |
} | |
return new FilterViewModel(); | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ "totalResults" : 1000, | |
"models" : [ | |
{"itemId" : 1, "itemName" : "1番目", "itemDesc" : "1番目だよ"}, | |
{"itemId" : 2, "itemName" : "2番目", "itemDesc" : "2番目だよ"}, | |
{"itemId" : 3, "itemName" : "3番目", "itemDesc" : "3番目だよ"} | |
]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ "models" : [ | |
{"itemId" : 1, "itemName" : "1番目", "itemDesc" : "1番目だよ"}, | |
{"itemId" : 2, "itemName" : "2番目", "itemDesc" : "2番目だよ"}, | |
{"itemId" : 3, "itemName" : "3番目", "itemDesc" : "3番目だよ"} | |
]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{"itemId" : 1, "itemName" : "1番目", "itemDesc" : "1番目だよ"}, | |
{"itemId" : 2, "itemName" : "2番目", "itemDesc" : "2番目だよ"}, | |
{"itemId" : 3, "itemName" : "3番目", "itemDesc" : "3番目だよ"} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment